Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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).

Ad
Log in to vote
0
Answered by 9 years ago

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)




0
You're still using the PlayerAdded event . Use LocalPlayer *instead* not *in addition* . . BlueTaslem 18071 — 9y
0
Still nothing. I tried game.Players.LocalPlayer:connect SprocketSoldier 0 — 9y
0
No ... There is absolutely no need to do any connections. BlueTaslem 18071 — 9y
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. SprocketSoldier 0 — 9y

Answer this question