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

Problem with a Teleportation Service Part ?

I got a problem when i'm trying to make a part that when you touch it, it make you teleport to another place, like the egg hunt (2014).

I'm working on a new game, I try to use no free models, please help me to know about this part of the job, please help me to fix it.

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
	game:GetService("TeleportService"):TeleportToSpawnByName(141257134, "SpawnLocation", player)
    end
end

Thank you. --TheDarkSpy07--

2 answers

You did not define when the function 'onTouched' should be called, here is how you can fix it:

function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
    game:GetService("TeleportService"):TeleportToSpawnByName(141257134, "SpawnLocation", player)
    end
end
game.Workspace.Part.Touched:connect(onTouched)--Just added this, it determines when to run your function.

2 comments

0

Okay thanks you.

0

Yep, no problem.

Or just make this all easier and insert the script into the part and do this

script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
    game:GetService("TeleportService"):TeleportToSpawnByName(141257134, "SpawnLocation", player)
    end
end)

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