Server removing more than it should?

Hello!

I was making a zombie value script for my zombie game, and for some reason it removes 3 values when dead instead of 1. Here’s the script.

local zombiesCount = (game.Workspace.serverValues.zombiesCount)
local zombieHumanoid = (script.Parent)

if zombieHumanoid then
	zombiesCount.Value = (zombiesCount.Value + 1)
	zombieHumanoid.Died:Connect(function()
		zombiesCount.Value = (zombiesCount.Value - 1)
	end)
end

By

do you mean decreases the value by 3?

1 Like

Yeah, not sure why it happens.

Maybe add a debounce because it might be firing multiple times? Try making the debounce something like 6 seconds

I tried something else, look.

local zombiesCount = (game.Workspace.serverValues.zombiesCount)
local zombieHumanoid = (script.Parent)

function removeZombieCount(removeValue)
	zombiesCount.Value = zombiesCount.Value - removeValue
end

function addZombieCount(addValue)
	zombiesCount.Value = zombiesCount.Value + addValue
end

if zombieHumanoid then
	addZombieCount()
	zombieHumanoid.Died:Connect(function()
		removeZombieCount()
	end)
end

It works, but still decreases by 3 everytime it dies for some reason.

Add the debounce, the only reason I can think it would do that would be because it is firing multiple times

Added it, still does the same thing for some reason.

This problem happened to me too, just use Debounce

Hmm, I believe that each zombie has these events so if there are three zombies died , three events will fire.

How long did you make the debounce?

1 Like

Wait, by debounce, do you mean wait or?

The script is in one zombie take a closer look

Yes, each zombie does have these events, but once ONE dies, it decreases by three.

Debounce is explained in this article on the Developer Hub.

1 Like

Added a wait(1) like this… (Still didn’t do it.)

local zombiesCount = (game.ServerStorage.serverValues.zombiesCount)
local zombieHumanoid = (script.Parent)

function removeZombieCount(removeValue)
	wait(1)
	zombiesCount.Value = zombiesCount.Value - removeValue
end

function addZombieCount(addValue)
	wait(1)
	zombiesCount.Value = zombiesCount.Value + addValue
end

if zombieHumanoid then
	addZombieCount(1)
	zombieHumanoid.Died:Connect(function()
		removeZombieCount(1)
	end)
end
local Debounce = false

zombieHumanoid.Died:Connect(function()
        if Debounce == false then
           Debounce = true
	      zombiesCount.Value = (zombiesCount.Value - 1)
         wait(0.5)
         Debouce = false
     end
end)
3 Likes

I’ll try that, give me a minute.

Why does the devforums minimize it to number i can’t say characters, ah.

This is what i meant by debounce:

if zombieHumanoid then
    db = false
    addZombieCount(1)
    zombieHumanoid.Died:Connect(function()
        if db == false then
            db = true
            removeZombieCount(1)
            wait(3)
            db = false
         end
    end)
end
1 Like

Sorry, didn’t know. I thought by debounce, you meant like wait(10).

Well, did my solution work for you?

2 Likes