Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I don't understand, what is wrong? {NOT SOLVED}

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)


2 answers

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)




4 comments

0

You're still using the PlayerAdded event . Use LocalPlayer instead not in addition . .

0

Still nothing. I tried game.Players.LocalPlayer:connect

0

No ... There is absolutely no need to do any connections.

0

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) -- I need the very last connection, it's a GUI button. Still won't work though.

This discussion is preserved as it was. New answers, comments, and votes are closed.