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