#My script won't put a model in the workspace for the client. (Still Unsolved)
1 messages · Page 1 of 1 (latest)
ok @trim apex
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UpdateShipMovementEvent = ReplicatedStorage:WaitForChild("UpdateShipMovementEvent")
-- Constants for server-side validation or limits (optional, but good practice)
-- Example: local MAX_SERVER_SPEED = 25
-- Example: local MAX_SERVER_ANGULAR_VELOCITY = 6
local function onUpdateShipMovement(player, speed, angularVelocity)
-- Validate inputs (optional, but recommended)
-- speed = math.clamp(speed, -MAX_SERVER_SPEED, MAX_SERVER_SPEED)
-- angularVelocity = math.clamp(angularVelocity, -MAX_SERVER_ANGULAR_VELOCITY, MAX_SERVER_ANGULAR_VELOCITY)
local shipName = player.DisplayName .. "'s Ship"
local shipModel = workspace:FindFirstChild(shipName)
if shipModel and shipModel:IsA("Model") then
local base = shipModel:FindFirstChild("Base")
if base and base:IsA("BasePart") then
-- Ensure the part is unanchored to allow physics-based movement
if base.Anchored then
-- This might indicate an issue if docking/undocking logic isn't perfectly synced
-- For now, we'll proceed assuming it should be movable
base.Anchored = false -- Make sure the part is not anchored
end
-- Calculate forward/backward velocity vector
local forwardVelocity = base.CFrame.LookVector * speed
-- Apply forward/backward velocity
base.AssemblyLinearVelocity = forwardVelocity
-- Apply angular velocity for turning (around the Y-axis of the ship's base)
-- The client sends positive angularVelocity for 'A' (left turn) and negative for 'D' (right turn).
-- A positive rotation around the Y-axis (0,1,0) is counter-clockwise (left).
-- `base.CFrame:VectorToWorldSpace(Vector3.new(0, math.rad(angularVelocity), 0))` converts local Y-axis rotation to world space.
base.AssemblyAngularVelocity = base.CFrame:VectorToWorldSpace(Vector3.new(0, math.rad(angularVelocity), 0))
else
warn("ShipMovementServer: Ship '" .. shipName .. "' does not have a 'Base' part.")
end
else
-- Ship not found, could be despawning or an issue.
-- warn("ShipMovementServer: Ship '" .. shipName .. "' not found for player " .. player.Name)
end
end
UpdateShipMovementEvent.OnServerEvent:Connect(onUpdateShipMovement)
print("ShipMovementServer Script Loaded and Connected.")
This is the server script
I need the script to do it for both client and server