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

What's wrong with the code to teleport to another location ?

Attention. I had used Google Translator , as do not know much English

What's wrong with the code to teleport to another place?

local TeleportService = game:GetService("TeleportService")
local level1Id = 241113670

 
function onClicked()
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(level1Id, player)
    end
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

This code is setup for a touched event

You're getting the player from hit.Parent but that doesn't exist. Click detectors return the player that clicked, so use that.

local TeleportService = game:GetService("TeleportService")
local level1Id = 241113670


function onClicked(player)
	TeleportService:Teleport(level1Id, player)
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Good Luck!

If I helped, please don't forget to accept my answer.

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