Trouble creating Debounce for two players

I’m trying to create a drag race system, I have the starting parts set up, but for the Finish Line part that gives players money for competing.
I can’t figure out how to create Debounce(for each racer I assume) so that each player only gets the designated amount of money for competing.
I’ve tried adding Debounce in multiple ways and locations, but either the first player gets all the money and maxes out the IntConstrainedValue (seen below) or it just doesn’t work at all.

local VictoryPart = script.Parent -- // Part we are going to touch
local PlayersFinished = VictoryPart.Parent.Values.PlayersFinished -- // IntConstrainedValue determining how many players are finished, 2 is max number
local LeftSpotPlayer = VictoryPart.Parent.Values.LeftSpotPlayer -- // (String) Player in the Left Spot
local RightSpotPlayer = VictoryPart.Parent.Values.RightSpotPlayer -- // (String) Player in the Right Spot
local LeftFinishRaceEvent = VictoryPart.Parent.Events.FinishRaceLeftSpot -- // Bindable Event that cleans up the starting part for the race (Left Spot)
local RightFinishRaceEvent = VictoryPart.Parent.Events.FinishRaceRightSpot -- // Bindable Event that cleans up the starting part for the race (Right Spot)

VictoryPart.Touched:Connect(function(Object)
	if Object:FindFirstAncestorWhichIsA("Model") and Object:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Humanoid") then -- // Don't worry about spaghetti code, checking to find Player
		local Character = Object:FindFirstAncestorWhichIsA("Model")
		local Player = game.Players:GetPlayerFromCharacter(Character) -- // Getting the Player for use blow
			if Player.Name == LeftSpotPlayer.Value or RightSpotPlayer.Value then -- // Checking to see if the known Player is the same as the two Racers
				local PlayerMoney = Player:WaitForChild("leaderstats").Money -- // Get player money
				PlayersFinished.Value = PlayersFinished.Value + 1 -- // Change the PlayersFinished Value by adding 1
				if PlayersFinished.Value == 1 then -- // If the value is 1, get the winning player and give them 2500
					PlayerMoney.Value = PlayerMoney.Value + 2500
				elseif PlayersFinished.Value == 2 then -- // If the value is 2, get the losing player and give them 500 instead
					PlayerMoney.Value = PlayerMoney.Value + 500
				end
				if Player.Name == LeftSpotPlayer.Value then -- // Check for LeftSpotPlayer so we can clean up their original starting place
					LeftFinishRaceEvent:Fire(Player)
			elseif Player.Name == RightSpotPlayer.Value then -- // Check for RightSpotPlayer so we can clean up their original starting place
					RightFinishRaceEvent:Fire(Player)
					end
			end
	end
end)

Here is a picture of the Explorer for better visualization:

Thanks for whatever help I’m offered, I added comments so people knew what everything was.

You can add something like a BoolValue into the player once they complete the race, and when you run that they complete the race you would check if their player had that BoolValue in them, if not, add the score and add the BoolValue.

At the time the next race starts you can loop through the players and remove any that have the BoolValue

You could also use CollectionService and assign everyone that crosses the finish line a tag such as “CompletedRace” and do a check to see if the player has that tag when they cross the end.

By the time the race ends, you can remove this tag from all the players.

1 Like