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

What do you guys think is wrong with this teleporting script where the robloxians won't teleport?

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.

local s = game:service("TeleportService")
local id = script.Name

script.Parent.Touched:Connect(function(onTouched)
	s:Teleport(id)
end)

2 comments

0

Code Hunters II opens on my birthday :D

0

Awesome, happy early birthday! :-D

2 answers

✓ Accepted answer

You forgot an argument. Also you need to get the player.

local s = game:service("TeleportService")
local id = script.Name

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")~=nil then
		s:Teleport(id, game.Players:GetPlayerFromCharacter(hit.Parent))
	end
end)

I took the player who touched and I added it as a argument to the function

2 comments

0

Ayyyye ninja'd ;D

0

@Goulstem ;P

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.

local s = game:service("TeleportService")
local id = script.Name

script.Parent.Touched:Connect(function(hit)
	local p = game.Players:GetPlayerFromCharacter(hit.Parent) --get player
	if p then
		s:Teleport(id,p)
	end
end)

1 comment

0

thankyou

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