I am trying to make a game where you search for codes it is called Code Hunters II and it is opening July 14th, 2017 so time is running out. This is a main thing I need done. I placed the script in the part that I want the people to touch to teleport to and script.Name is the id I used to teleport to the map. Please help me the script is below I do not know the bug. It was working a few weeks ago and then suddenly it no longer worked! I want to make then teleport to another game btw.
1 | local s = game:service( "TeleportService" ) |
2 | local id = script.Name |
3 |
4 | script.Parent.Touched:Connect( function (onTouched) |
5 | s:Teleport(id) |
6 | end ) |
You forgot an argument. Also you need to get the player.
1 | local s = game:service( "TeleportService" ) |
2 | local id = script.Name |
3 |
4 | script.Parent.Touched:Connect( function (hit) |
5 | if hit.Parent:FindFirstChild( "Humanoid" )~ = nil then |
6 | s:Teleport(id, game.Players:GetPlayerFromCharacter(hit.Parent)) |
7 | end |
8 | end ) |
I took the player who touched and I added it as a argument to the function
If you're using the Teleport
function of TeleportService from the server, you have to supply the Player argument.
You can retrieve the Player object using GetPlayerFromCharacter
.
1 | local s = game:service( "TeleportService" ) |
2 | local id = script.Name |
3 |
4 | script.Parent.Touched:Connect( function (hit) |
5 | local p = game.Players:GetPlayerFromCharacter(hit.Parent) --get player |
6 | if p then |
7 | s:Teleport(id,p) |
8 | end |
9 | end ) |