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

What is wrong with this Teleport Script?

Asked by
Japhie 20
10 years ago

I have a base underneath the map where players spawn. When they click the button I want them to be teleported to a specified place on the map. This is what I've tried:

function onClick()
    game.Workspace.Player.Torso.CFrame = CFrame.new(Vector3.new(0, 5, 0))
end

script.Parent.MouseButton1Click(onClick)

Is it just me or does it seem to short?

2 answers

Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

If it is a TextButton in the PlayerGui, then you can modify this:

local plr = game.Players.LocalPlayer

function onClick()
    game.Workspace[plr.Name].Torso.CFrame = CFrame.new(Vector3.new(0, 5, 0))
end

script.Parent.MouseButton1Click:connect(onClick)

EDIT: I never noticed the :connect missing, thanks.

0
Unfortunately that doesn't work. I tried fixing it with my limited knowledge but I couldn't find anything wrong with it. It just doesn't work Japhie 20 — 10y
0
Try using a regular script. Dummiez 360 — 10y
0
You could use :MoveTo() OniiCh_n 410 — 10y
0
Ok thank you, this now works! Japhie 20 — 10y
Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago
local player = game.Players.LocalPlayer -- LocalScript only

function onClick()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0, 5, 0))
end

script.Parent.MouseButton1Click:connect(onClick)

The event wasn't connected to the function. (:connect()) Also, use a LocalScript for this.

Answer this question