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 11 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.

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

Thank you. --TheDarkSpy07--

2 answers

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

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

1function onTouched(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
3    if player then
4    game:GetService("TeleportService"):TeleportToSpawnByName(141257134, "SpawnLocation", player)
5    end
6end
7game.Workspace.Part.Touched:connect(onTouched)--Just added this, it determines when to run your function.
0
Okay thanks you. TheDarkSpy07 5 — 11y
0
Yep, no problem. ultrabug 306 — 11y
Ad
Log in to vote
-2
Answered by 11 years ago

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

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

Answer this question