I am trying to get it to teleport a player, lock their torso, and lock their camera in first person all at the same time once they click a gui button. I can't find why it's not working, but it's not. Help?
function Click() game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(-0,0,0) game.Players.LocalPlayer.Character.Torso.Anchored=true end wait() game.Players.LocalPlayer.CameraMode="LockFirstPerson" game.StarterGui.FNMain.Frame.Visible = false script.Parent.MouseButton1Down:connect(Click)
When you use a connect
line, it starts listening from then on. That means, when every someone presses this button, it starts doing whatever for the next player to join.
If this is a button in the PlayerGui
then use either game.Players.LocalPlayer
or the appropriate script.Parent.Parent....
to get to the player's character.
Connecting to one event inside of another is almost never what you want (exceptions would be when you are connecting to newly created objects).
Yeah, I tweaked it using game.Players.LocalPlayer
but that didn't do the trick.
function Click() game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new(-0,0,0) game.Players.PlayerAdded:connect(function(plr) repeat wait() until plr.Character plr.Character.Torso.Anchored=true end) end wait() game.Players.LocalPlayer.CameraMode="LockFirstPerson" game.StarterGui.FNMain.Frame.Visible = false script.Parent.MouseButton1Down:connect(Click)