I have a script that allows players to control the rotation of a part, which a camera is attached to. Parts are cloned from ServerStorage via another script and named after the player in control.
The script works flawlessly with only one player in the server, but once multiple players join, only the first player that joined is able to control it.
Video demonstration:
This is the code in question. I’ve mostly ruled out it being the cloning script, as placing the parts into Workspace manually has the same effect.
local camera = workspace.CurrentCamera
local run = game:getService("RunService")
local player = game:GetService("Players")
local mouse = player.LocalPlayer:GetMouse()
wait(1)
local plane = workspace:WaitForChild(player.LocalPlayer.Character.Name .. "Plane")
local gyro = plane.BodyGyro
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = plane
local tilt = 40
run.Heartbeat:Connect(function()
camera.CFrame = plane.Attachment.WorldCFrame
gyro.CFrame = CFrame.new(plane.Position) * CFrame.Angles(
math.rad((((mouse.X - mouse.ViewSizeY / 1.5) / (mouse.ViewSizeX) * tilt))),
0,
math.rad(((((mouse.Y - mouse.ViewSizeY / 1.5) / (mouse.ViewSizeY)) * -tilt)))
)
end)
However, just to be sure, this is the relevant code from the cloning script.
players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
wait()
local storage = game:GetService("ServerStorage")
local clone = storage.plane:Clone()
clone.Parent = workspace
clone.Name = (player.Name .. "Plane")
game.Workspace.ChildAdded:connect(function(character)
if game.Players:GetPlayerFromCharacter(character) then
character:WaitForChild("ForceField"):Destroy()
character.Parent = storage --parents the controller player to serverstorage so it is not visible in workspace
end
end)
Despite what I said before, I’ve noticed that the player removal runs multiple times for each player that joins after the first one, which may have something to do with the issue. However, I do not know for sure.