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

Not teleporting player to a different game when the click the button?

Asked by 6 years ago
Edited 6 years ago

So, I'm not gonna lie, this code is from a free model. Nonetheless, it doesn't work. I have a button that; when you click it; **** should **** teleport you to a different map. But it doesn't. here is the code:


script.Parent.MouseButton1Click:connect(function() --what fires all the code 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 end)

if anyone can help me, it would be much appreciated.

the int valie "DestinationSpawnName" and "PlaceId" are put into the local script. This local script is put into the button.

0
Try placeId = {} and spawnName = {} no idea if that'd work tbh Godlydeathdragon 227 — 6y
0
doesn't work 0HappyManDudeguy0 15 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Here's what I did and it worked. Instead of using an IntValue I used a string value for the spawn name and a number value for the place Id and it worked.

script.Parent.MouseButton1Click:connect(function() --what fires all the code
local place = script:FindFirstChild("PlaceId")
local spaw = script:FindFirstChild("DestinationSpawnName")

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

Answer this question