I'm making a round script where when somebody steps on a part, they get teleported back to the lobby and the script adds one value for TotalCountedPlayers that stepped on that part. The problem is that I set a print function and it's printing more than once even with debounce.
if plr and char and plr:FindFirstChild('GameTag') then for _, TaggedParts in pairs(CollectionService:GetTagged("ObbyRewardsTag")) do TaggedParts.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local char = plr.Character local hum = char:FindFirstChild("Humanoid") local humRootPart = char:FindFirstChild("HumanoidRootPart") local DB = false if plr and char and DB == false and hum and humRootPart and plr:FindFirstChild("GameTag") then DB = true TotalCountedPlayers.Value = TotalCountedPlayers.Value + 1 plr.LeaderStatsFolder.Stonks.Value = plr.LeaderStatsFolder.Stonks.Value + RandomAmount humRootPart.CFrame = LobbySpawner[1].CFrame table.remove(LobbySpawner, 1) DB = false wait(.5) print("Went Up By One") end end) end end end
Your problem is simply that you are yielding after you set debounce to false. Debounce will only work if you set it back to false after you wait the desired amount of time. This is a super simple fix and would cause your script to look like this:
local DB = false if plr and char and plr:FindFirstChild('GameTag') then for _, TaggedParts in pairs(CollectionService:GetTagged("ObbyRewardsTag")) do TaggedParts.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local char = plr.Character local hum = char:FindFirstChild("Humanoid") local humRootPart = char:FindFirstChild("HumanoidRootPart") if plr and char and DB == false and hum and humRootPart and plr:FindFirstChild("GameTag") then DB = true TotalCountedPlayers.Value = TotalCountedPlayers.Value + 1 plr.LeaderStatsFolder.Stonks.Value = plr.LeaderStatsFolder.Stonks.Value + RandomAmount humRootPart.CFrame = LobbySpawner[1].CFrame table.remove(LobbySpawner, 1) wait(.5) print("Went Up By One") DB = false end end) end end end
Simple as that! Let me know if this still gives you problems and I'll see if I can find anything else.
EDIT: What I've changed is where you are setting the debounce to false. You used to be setting it to false every single time the event ran (at least I'm assuming you're using a touched event) which means that the debounce will never be true. If you set it at the beginning of the script instead of inside the event your problem should now be fixed.