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

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

Asked by 7 years ago

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)
0
Code Hunters II opens on my birthday :D Goulstem 8144 — 7y
0
Awesome, happy early birthday! :-D Goldenkings11 -11 — 7y

2 answers

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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

0
Ayyyye ninja'd ;D Goulstem 8144 — 7y
0
@Goulstem ;P DanzLua 2879 — 7y
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

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)
0
thankyou Goldenkings11 -11 — 7y

Answer this question