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

Problem with a Teleportation Service Part ?

Asked by 10 years ago

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

Log in to vote
4
Answered by
ultrabug 306 Moderation Voter
10 years ago

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.
0
Okay thanks you. TheDarkSpy07 5 — 10y
0
Yep, no problem. ultrabug 306 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

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)

Answer this question