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

My function to teleport a player to somewhere doesn't work?

So, sorry.. I'm not too good at scripting... I made a GUI that teleports a player to somewhere when they click it and don't know why it doesn't work..

function clicked (click)
	local target = CFrame.new(189.87, 69.6, -216.3)
	player = click.Parent:FindFirstChild("Torso")
	player.CFrame = target
end

script.Parent.MouseButton1Click:connect(clicked)

AND, output said this when I clicked the GUI to test:

18:44:31.449 - Players.Player.PlayerGui.BattlefieldTeleportGUI.TextButton.:4: attempt to index local 'click' (a nil value) 18:44:31.451 - Stack Begin 18:44:31.453 - Script 'Players.Player.PlayerGui.BattlefieldTeleportGUI.TextButton.', Line 4 18:44:31.454 - Stack End

2 answers

✓ Accepted answer

Don't do that use this:

plr = script.Parent(you need parents until the parent of startergui, the parent of startergui is the player)

the click is a parameter for mouse, not for the button, also try :WaitForChild i find it more affective

2 comments

0

Ok, I'll try it....

0

worked

I'd recommend using :MoveTo() in this case, besides it's easier to understand if you aren't that good at scripting.

All you have to do its create a part and put it inside workspace in the position you want to teleport the character to.

function clicked (click)
	local player = game.Players.LocalPlayer -- make sure it's a LocalScript
	player.Character:MoveTo(Workspace.Part.Position) -- Move the Character to your part
end

script.Parent.MouseButton1Click:connect(clicked)

Hope this helped..

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