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

What is wrong with this Teleport Script?

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

✓ Accepted answer

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.

4 comments

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

0

Try using a regular script.

0

You could use :MoveTo()

0

Ok thank you, this now works!

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.

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