Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

0

Try placeId = {} and spawnName = {} no idea if that'd work tbh

0

doesn't work

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.