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

Why It Gives me 3 Points when I touch the Part?

Asked by
Borrahh 265 Moderation Voter
4 years ago
game.Players.PlayerAdded:Connect(function(plr) 
local stats = Instance.new("StringValue", plr)

    stats.Name = "leaderstats"

    local wins = Instance.new("IntValue", stats)
    wins.Name = "Wins"
    wins.Value = 0

local debounce = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    if hit.Parent.Humanoid.Health > 0 then

    if debounce == false then
        debounce = true

        print("You win")
    script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
    wins.Value = wins.Value + 1 
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(234, 45.906, -114) end end)
wait(4)
debounce = false
    end 
    else
        print("You lost")
        end
        end
end)
end)

So Basically, when you touch the part, its supposed to give you 1 win only, but however it gives me 3 wins

2 answers

Log in to vote
1
Answered by 4 years ago

You don’t need to have two touched events! If you remove the second touched event, it should work.

Ad
Log in to vote
0
Answered by
Ciyob86 25
4 years ago

Follow the first answer if it does not work then just put a wait(1) so their is a cool down.

Answer this question