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.
1 | function onTouched(hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player then |
4 | game:GetService( "TeleportService" ):TeleportToSpawnByName( 141257134 , "SpawnLocation" , player) |
5 | end |
6 | end |
Thank you. --TheDarkSpy07--
You did not define when the function 'onTouched' should be called, here is how you can fix it:
1 | function onTouched(hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player then |
4 | game:GetService( "TeleportService" ):TeleportToSpawnByName( 141257134 , "SpawnLocation" , player) |
5 | end |
6 | end |
7 | game.Workspace.Part.Touched:connect(onTouched) --Just added this, it determines when to run your function. |
Or just make this all easier and insert the script into the part and do this
1 | script.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 |
6 | end ) |