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

Touched runs for all players even when it's in a local script?

Asked by 6 years ago
Edited 6 years ago

I have a teleporting script and a part that detects if it got touched by a player and teleports the player that touched it. But it's not working as it's supposed to. It's teleporting ALL players. Even players that hasn't even touched it.

The script looks something like this but it's not the real script.

part.Touched:Connect(function(p)

    local plr = game.Players:GetPlayerFromCharacter(p.Parent)

    if plr ~= nil then
    player.Character.Humanoid.Torso.CFrame = CFrame.new(206.25, -159.5, -1833)
    end

end)
0
We cannot answer a question if you do not give us the full script, also I don't think touched works in a local script and it sure doesn't work if it's inside the workspace and a local script User#20388 0 — 6y
0
There isn't much to the script other than this part. xXrawr_xdXxOwO 24 — 6y
1
you don't have the 'teleport' code? thats where the problem occurs. awesomeipod 607 — 6y
1
Ok I added the teleport code. xXrawr_xdXxOwO 24 — 6y
1
ok try my answer out awesomeipod 607 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
part.Touched:connect(function(hit)
    if hit then 
        if hit.Parent:FindFirstChild('Humanoid') and game.Players:FindFirstChild(hit.Parent.Name) then 
            local player = game.Players:FindFirstChild(hit.Parent.Name)
            player.Character.HumanoidRootPart.CFrame = CFrame.new(206.25, -159.5, -1833) -- paste the position you want the player to teleport to here
        end
    end
end)
1
. awesomeipod 607 — 6y
1
hope this works, accept it if it does awesomeipod 607 — 6y
1
Thank you!!!!!! This works perfectly and only teleports the player that touched the part. xXrawr_xdXxOwO 24 — 6y
1
:D np awesomeipod 607 — 6y
Ad

Answer this question