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

gives point to player if on red team and touch part, but debounce doesn't work. How do I fix it?

Asked by 1 year ago

local Players = game:GetService("Players")

local Teams = game:GetService("Teams")

local debounce = true

game.Players.PlayerAdded:Connect(function(player)

if player.Team == Teams["Red Team"] then
    script.Parent.Touched:Connect(function(hit)
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player then
            debounce = false
            player.leaderstats.Points.Value += 1
            wait(3)
            debounce = true

        end
    end)
end

end)

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

You need to put the if statement within the Touched event; that way, it will check if the player is on 'Red Team' when they touch the part.

Also, the PlayerAdded event is unnecessary.

local Players = game:GetService("Players")

local Teams = game:GetService("Teams")

local debounce = false

script.Parent.Touched:Connect(function(hit)

    local player = Players:GetPlayerFromCharacter(hit.Parent)

    if player and player.Team == Teams["Red Team"] then
        if debounce then return end -- If the debounce is active, it will return to the function, preventing the function from continuing.
        debounce = true
        player.leaderstats.Points.Value += 1
        task.wait(3)
        debounce = false
    end
end)
0
xInfinity Bear thank you so much but do you know how to make it so when it gives a play the 1 point it then makes a frame visible then kills all players and makes the frame non-visible again? Thank You MariamOMG090 9 — 1y
Ad

Answer this question