Whenever I start the game it does everything correctly except anchor the player's character on the cam part. It goes right through the code for anchoring the player's character so no errors, it just doesn't work like it should. My first thought was, maybe the camera isn't loaded in or something so I had it wait till the camera loaded in but that didn't work. So I'm here. Thx in advance for any help. server script in ServerScriptService
game.Players.PlayerAdded:Connect(function(plr) for _, Spawn in pairs(workspace.Spawns:GetChildren()) do if Spawn.Available.Value then Spawn.Available.Value = false game.ReplicatedStorage.Events.Spawn:FireClient(plr, Spawn) break end end end) game.ReplicatedStorage.Events.Spawn.OnServerEvent:Connect(function(plr, Spawn) game.ReplicatedStorage.Events.Spawn:FireClient(plr, Spawn) end)
My LocalScript in StarterPlayerScripts (look to line 6)
local Sp game.ReplicatedStorage.Events.Spawn.OnClientEvent:Connect(function(Spawn) local cam = workspace.CurrentCamera cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = Spawn.Cam.CFrame local S = Spawn.Spawn Sp = Spawn repeat wait() until game.Players.LocalPlayer.Character repeat wait() until game.Players.LocalPlayer.Character:FindFirstChild('Humanoid') game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0 game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0 game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(S.Position.X, S.Position.Y + 15, S.Position.Z)) end) while true do repeat wait() until game.Players.LocalPlayer.Character if game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Health <= 0 and game.Players.LocalPlayer.PlayerGui.StartScreen.Enabled then wait(5) game.ReplicatedStorage.Events.Spawn:FireServer(Sp) end end
You can't teleport a player using a local script, it can only be done through the server. This is because teleporting a player through the client only allows the single Player to see it, not the other players. This can be fixed by simply using a remote function to fire an event that teleports a player to a certain position.
Example:
In server (Script):
local RemoteEvent = game.ReplicatedStorage.TeleportPlayer RemoteEvent.OnServerEvent:connect(function(plr) local Char = plr.Character Char.HumanoidRootPart.CFrame = CFrame.new() -- Whatever the CFrame of the torso needs to be end)
In client (LocalScript):
local RemoteEvent = game.ReplicatedStorage.TeleportPlayer RemoteEvent:FireServer()
I hope this is of some use to you! If not, let me know how else I can help! :)