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

Gui Button Help?

Asked by 10 years ago

Trying to get it where when you click the button it teleport but it teleport you when you join, Can someone help me please?

wait()
local place = script:FindFirstChild("PlaceId")
local spawn = script:FindFirstChild("DestinationSpawnName")

local placeId
local spawnName
if place then
    placeId = place.Value
    if spawn and spawn.Value then
        spawnName = spawn.Value
        game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName)
    else
        game:GetService("TeleportService"):Teleport(placeId)
    end
end

0
function onClicked() at the top it gives a error GuardainDev 45 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago
function onClick()

local place = script:FindFirstChild("PlaceId")
local spawn = script:FindFirstChild("DestinationSpawnName")

if place then
    placeId = place.Value
    if spawn then
        spawnName = spawn.Value
        game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName)
    else
        game:GetService("TeleportService"):Teleport(placeId)
    end
end

script.Parent.MouseButton1Down:connect(onClick) --The script's parent should be the brick you want to click

Rember to add the values!

Ad
Log in to vote
1
Answered by 10 years ago

Okay, you've got a few things wrong here. First of all, the local place and local spawn will only work if there is something in the Script, such as a value. Also, you have set two variables to nil values. You should remove local placeId and local spawnName from the script altogether, because those would screw things up.

I'm not sure what the Teleport event tag is, but I'm not sure if :TeleportToSpawnByName is correct, so you should probably check that.

And remove spawn.Value from the 9th line, all you need is if spawn then.

Lastly, you need a function and a connection line. And make sure that there is a Click Detector in the brick you want.

Here's the edited code:


function onClick() local place = script:FindFirstChild("PlaceId") local spawn = script:FindFirstChild("DestinationSpawnName") if place then placeId = place.Value if spawn then spawnName = spawn.Value game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName) else game:GetService("TeleportService"):Teleport(placeId) end end script.Parent.MouseButton1Down:connect(onClick) --The script's parent should be the brick you want to click

If that doesn't work, let me know. Check your output when you run the script.

0
Its a Gui TextButton btw and the script dont give me any errors here how i wrote it ; function onClick() local place = script:FindFirstChild("PlaceId") local spawn = script:FindFirstChild("DestintionSpawnName") if place then placeId = place.Value if spawn then SpawnName = spawn.Value game:GetService("TeleportService"):TeleportToSpawnByName(placeID) else game:GetService("TeleportService GuardainDev 45 — 10y

Answer this question