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?

01wait()
02local place = script:FindFirstChild("PlaceId")
03local spawn = script:FindFirstChild("DestinationSpawnName")
04 
05local placeId
06local spawnName
07if place then
08    placeId = place.Value
09    if spawn and spawn.Value then
10        spawnName = spawn.Value
11        game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName)
12    else
13        game:GetService("TeleportService"):Teleport(placeId)
14    end
15end
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
01function onClick()
02 
03local place = script:FindFirstChild("PlaceId")
04local spawn = script:FindFirstChild("DestinationSpawnName")
05 
06if place then
07    placeId = place.Value
08    if spawn then
09        spawnName = spawn.Value
10        game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName)
11    else
12        game:GetService("TeleportService"):Teleport(placeId)
13    end
14end
15 
16script.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:

01function onClick()
02 
03local place = script:FindFirstChild("PlaceId")
04local spawn = script:FindFirstChild("DestinationSpawnName")
05 
06if place then
07    placeId = place.Value
08    if spawn then
09        spawnName = spawn.Value
10        game:GetService("TeleportService"):TeleportToSpawnByName(placeId, spawnName)
11    else
12        game:GetService("TeleportService"):Teleport(placeId)
13    end
14end
15 
16script.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