I have this old teleport script that I converted to work with R15 so it works with my new game. And I want to convert the script so when you click the GUI that is on the wall it teleports you. But I dont know how id go about this, here is the script.
-- Model it teleports to
------------------------------------
modelname="tele4"
------------------------------------
function onTouched(part)
if part.Parent ~= nil then
local h = part.Parent:findFirstChild("Humanoid")
if h~=nil then
local teleportfrom=script.Parent.Enabled.Value
if teleportfrom~=0 then
if h==humanoid then
return
end
local teleportto=script.Parent.Parent:findFirstChild(modelname)
if teleportto~=nil then
local torso = h.Parent.UpperTorso
local location = {teleportto.Position}
local i = 1
local x = location[i].x
local y = location[i].y
local z = location[i].z
x = x + math.random(-1, 1)
z = z + math.random(-1, 1)
y = y + math.random(2, 3)
local cf = torso.CFrame
local lx = 0
local ly = y
local lz = 0
script.Parent.Enabled.Value=0
teleportto.Enabled.Value=0
torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
wait(3)
script.Parent.Enabled.Value=1
teleportto.Enabled.Value=1
else
print("Could not find teleporter!")
end
end
end
end
end
script.Parent.Touched:connect(onTouched)
UPDATE - Okay so I put the SurfaceGUI under StarterGUI and I put the script under TextButton. So it goes like this - StarterGUI.SurfaceGUI.TextButton.TeleportScript I dont know if I should move the teleport script up 1 so its directly under SurfaceGUI or what.
Heres the script so you know what your looking at
I should also mention its a localscript at the moment, I dont know if I should change it to a default script or what?
local plr = game.Players.LocalPlayer --This is the client
local char = plr.Character or plr.CharacterAdded:Wait() --This is the character
local root = char:WaitForChild("HumanoidRootPart") --This is the HumanoidRootPart
local teleportTo = workspace.RightExitDoor --This is where you teleport to!
local guiButton = game.StarterGui.SurfaceGui.TextButton --This is the button you're clicking!
guiButton.MouseButton1Down:Connect(function() --MouseButton1Down event
root.CFrame = teleportTo.CFrame * CFrame.new(0,3,0) --Set the root's CFrame to the teleportobject's CFrame, translate it up by 3 studs
end)

15 comments
Is that script just the bare bones, meaning it wont work. I know Ill have to change some things obviously. But will it work if it do? Also where do you put the script.?
All you need is a MouseButton1Down event and when it's clicked use the MouseButton1Down paramter to get the player then do Player.Character.HumanoidRootPart.CFrame = CFrame.new(0,0,0) To teleport them.
@GottaHaveAFunTime It will work. And you put that in the button.
@Shadi432 The MouseButton1Down event doesn't return the player who clicked. You're thinking of the MouseClick event of ClickDetectors.
@Goulstem It doesnt seem to be working
@Goulstem I placed it under SurfaceGUI.TextButton and it doesnt seem to be working.
Hmm.. is the SurfaceGui parented to StarterGui? If it isn't, move it there and set it's
Adorneeproperty to the object you want the ui to appear on.@Goulstem I updated the post ingeneral so look at the main post above and it has more info. Maybe that will help out a little bit. :)
Alright, the problem is how you define the
guiButtonvariable - since the script is a direct descendant of the button, you can simply do:guiButton = script.ParentIt still doesnt work man. I have no clue why its not working.
WAIT! OMGSHHHH ITS WORKING YAYYYYY FINALLYYYYY..... I mean... Thank you so much for not just giving up and thanks for helping me out :)
No problem :) Happy developing!
Ive just got 1 more question. if there a way I could make it so they cant spam the teleport button so there is like a timer between click.
Mhmm. This question is getting quite filled up, though. Ask another and both of us can recieve more rep :D
Thats a good point. Sorry im just getting used to all this scripting, I usually Animate and build so its all new to me.