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