So as i had previously asked, my code won't give me one kill per kill. I get more then one kill. So I added a debouce system. Now, instead of getting any points, i get none. Why does that happen? Here is my script.
ball = script.Parent damage = 50 local debounce = true function onTouched(hit) local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid~=nil then tagHumanoid(humanoid) humanoid.Health = humanoid.Health - damage if debounce then debounce = false if humanoid.Health == 0 or humanoid.Health < 0 then local z = game.Players:FindFirstChild(game.ReplicatedStorage.asd.Value) z.leaderstats.Kills.Value += 1 wait(2) debounce = true end end untagHumanoid(humanoid) connection:disconnect() else damage = damage / 2 if damage < 2 then connection:disconnect() ball.Parent = nil end end
In this instance do not use connection:Disconnect
because it stops the function.
ball = script.Parent damage = 50 local debounce = true function onTouched(hit) local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid~=nil then tagHumanoid(humanoid) humanoid.Health = humanoid.Health - damage if debounce then debounce = false if humanoid.Health == 0 or humanoid.Health < 0 then local z = game.Players:FindFirstChild(game.ReplicatedStorage.asd.Value) z.leaderstats.Kills.Value += 1 wait(2) debounce = true end end untagHumanoid(humanoid) else damage = damage / 2 if damage < 2 then ball.Parent = nil end end
don't use connection:Disconnect() on this situation, if it dont have lines it doesnt run anything, connection:Disconnect() only stops the function and it's unable to get listened, basically disable the function
Heres a very cool explanation by roblox:
Always call Disconnect() when a connection is no longer needed. Forgetting to do so can cause your game to use more resources than necessary. Note, however, that this may not always be necessary; when an object is destroyed, all connections to that object’s events are disconnected automatically.