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

Big problem in my game. (makes everyone teleport to my stage) ?

Asked by 4 years ago
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
wait(0.1)
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.CFrame

   end
end)
end)
end)

this for some reason makes every player teleport to the stage i am at when dying and touching one of these parts with this script in it ^^

Please help!

2 answers

Log in to vote
0
Answered by 4 years ago
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.Position)
end
end)

this will get the player from the touch (never use the characteradded function when you want the player who touched it) and teleports them to the place they should be on

0
Thanks alot! popu2004 42 — 4y
Ad
Log in to vote
0
Answered by
Fad99 286 Moderation Voter
4 years ago
Edited 4 years ago
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        wait(0.1)
        script.Parent.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") then
                if hit.Parent.Name == character.Name then
                    hit.Parent.HumanoidRootPart.CFrame = game.Workspace:FindFirstChild(tostring(player.leaderstats.Stage.Value)).CC.CFrame
                end
            end
        end)
    end)
end)

This should work, the problem with your script was that it wasent checking who touched it, because that touched event is running for everyone. instead you have to check if the person that wants to teleport was the person that actually touched it.

Answer this question