Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.