✓ Accepted answer
As stated by Dino, you'd have to use a debounce. Basically, this stops a function from running too many times.
To implement it, you need to initialize a boolean value which in your case could be done directly below HoleValue. To avoid confusion we'll just call it debounce.
local HoleValue = 1
local debounce = false
Now, how do you use a debounce? You will have to use a conditional if statement at the start of your function to check if debounce is equal to false.
script.Parent.Touched:Connect(function(hit)
if not debounce then
if hit.Parent:WaitForChild("Humanoid") then
local PlayerName = hit.Parent.Name
local Multiplier = game.Players[PlayerName].leaderstats.Multipliers.Value
hit.Parent.Humanoid.Health = 0
local EsimateValue = HoleValue * Multiplier
game.Players[PlayerName].leaderstats.Oofs.Value
game.Players[PlayerName].leaderstats.Oofs.Value + EsimateValue
end
end)
The next step is hopefully quite obvious. We need to set the debounce to true when we begin the function and false when it is finished.
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit.Parent:WaitForChild("Humanoid") then
local PlayerName = hit.Parent.Name
local Multiplier = game.Players[PlayerName].leaderstats.Multipliers.Value
hit.Parent.Humanoid.Health = 0
local EsimateValue = HoleValue * Multiplier
game.Players[PlayerName].leaderstats.Oofs.Value = game.Players[PlayerName].leaderstats.Oofs.Value + EsimateValue
debounce = false
end
end)
On top of this, you would need to add some sort of conditional as this alone won't stop multiple points being given. As I don't want to spoon feed you the answer, and I also do not want to give you false information, I'll give you some prompts:
Wait a few seconds before switching debounce to false
Con: If two people touch it within that time, it will only work for the first
Store the player in a table, check if they're in it, wait for a period of time and then remove them
Con: There are easier ways
I will try to give you a proper answer when i'm not so tired
5 comments
just use a debounce
That alone wouldn't work, as when the player dies, they could stay on the pad and it would repeat
pad? i read the code as you gaining a point for killing "something", so i figure just adding a db/delay would allow the enemy to die.
i also assumed he knew what a debounce was, and i probably shouldn't have, good explanation turtle!
Thank you, although I always feel like I'm spoonfeeding or giving false info, I annoy myself xD