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

Why is this teleport script working in Studio, but not online in the game?

Asked by
EpicLilC 150
8 years ago

So I made a teleport script using Players instead of using game.Workspace.Player:MoveTo...

function onTouch(plr)
game.Players.Player.Character:MoveTo(Vector3.new(21, 66.9, -96.5))
end
game.Workspace.Teleporter.Touched:connect(onTouch)

and it works, but it doesn't work online? Why , and what am I doing wrong? I thought that if I used Players instead of using Workspace.Players it would work..

2 answers

Log in to vote
3
Answered by 8 years ago

Your script assumes that the player's name is Player, you have to change that. In your code, the argument plr is the part that touched the teleport, which will most likely belong to some player's character. I've changed it to hit, as that makes more sense.

function onTouch(hit)
    if hit.Parent then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            player.Character:MoveTo(Vector3.new(21, 66.9, -96.5))
        end
    end
end
game.Workspace.Teleporter.Touched:connect(onTouch)
Ad
Log in to vote
0
Answered by
adatax 5
8 years ago

I believe the issue was in line 2, the way you where getting the player. you did not specify what Player was. The script automatically assumes the players name is Player Code

function onTouch(plr)
plr.Parent:MoveTo(Vector3.new(21, 66.9, -96.5))
end
game.Workspace.Teleporter.Touched:connect(onTouch)

Hope this helps!

Answer this question