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

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

Asked by
lucas4114 607 Moderation Voter
9 years ago

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

Log in to vote
0
Answered by
wackem 50
9 years ago

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

0
Ok, I'll try it.... lucas4114 607 — 9y
0
worked lucas4114 607 — 9y
Ad
Log in to vote
0
Answered by
Drogb4 15
9 years ago

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

Answer this question