Trying to get it where when you click the button it teleport but it teleport you when you join, Can someone help me please?
01 | wait() |
02 | local place = script:FindFirstChild( "PlaceId" ) |
03 | local spawn = script:FindFirstChild( "DestinationSpawnName" ) |
04 |
05 | local placeId |
06 | local spawnName |
07 | if 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 |
15 | end |
01 | function onClick() |
02 |
03 | local place = script:FindFirstChild( "PlaceId" ) |
04 | local spawn = script:FindFirstChild( "DestinationSpawnName" ) |
05 |
06 | if 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 |
14 | end |
15 |
16 | script.Parent.MouseButton 1 Down:connect(onClick) --The script's parent should be the brick you want to click |
Rember to add the values!
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:
01 | function onClick() |
02 |
03 | local place = script:FindFirstChild( "PlaceId" ) |
04 | local spawn = script:FindFirstChild( "DestinationSpawnName" ) |
05 |
06 | if 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 |
14 | end |
15 |
16 | script.Parent.MouseButton 1 Down: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.