I am making an object that drops HP every time the client is fired, when the HP reaches 0, it will fire to the server to give the player a stat
When the HP reaches 0 and the server is fired, it runs the code like 25 times instead of once
Ive tried adding a debounce but it does not solve the problem
Here is the localscript
local remote = game.ReplicatedStorage.Remotes.Geodes.BasicGeode
local config = game.Workspace.Buttons.Geodes.BasicGeode.config
local HP = config.HP.Value
local remote2 = game.ReplicatedStorage.Remotes.Geodes.BasicGeodeHand
local debounce = true
remote.OnClientEvent:Connect(function()
HP = HP - 1
config.Parent.part.BillboardGui.HP.Text = "HP: ("..HP.."/"..config.HP.Value..")"
if HP <= 0 then
if debounce then
debounce = false
HP = config.HP.Value
remote2:FireServer()
task.wait(5)
debounce=true
end
end
end)
Here is the serverscript
local x = require(game.ReplicatedStorage.EternityNum) -- To use the bignum.
local config = script.Parent.config
local remote = game.ReplicatedStorage.Remotes.Geodes.BasicGeode
local remote2 = game.ReplicatedStorage.Remotes.Geodes.BasicGeodeHand
local HP = config.HP.Value
script.Parent.part.BillboardGui.HP.Text = "HP: ("..HP.."/"..config.HP.Value..")"
script.Parent.part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") then
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local s = plr:FindFirstChild("Stats")
local money = plr.Stats:FindFirstChild("Money")
local multi = plr.Stats:FindFirstChild("Multi")
local dirt = plr.Stats:FindFirstChild("Dirt")
local stone = plr.Stats:FindFirstChild("Stone")
local diamond = plr.Stats:FindFirstChild("Diamond")
local gg = plr.Stats:FindFirstChild("GeodeMaster")
local geodeopen = plr.Stats:FindFirstChild("GeodesOpened")
local random1 = x.floor(x.rand({1,0} , x.convert(config.RNG1.Value)))
local random2 = x.floor(x.rand({1,0} , x.convert(config.RNG2.Value)))
local random3 = x.floor(x.rand({1,0} , x.convert(config.RNG3.Value)))
if multi == nil then return false end
if x.meeq(x.convert(multi.Value),(x.convert(config.cost.Value))) then
local s = x.convert(multi.Value)
local v = x.convert(config.cost.Value)
s = x.sub(s,v)
multi.Value = x.bnumtostr(s)
remote:FireClient(plr)
remote2.OnServerEvent:Connect(function()
if x.eq(random1 , {1,0} ) then
local svb = x.convert(dirt.Value)
local val =x.convert(config.amount.Value)
local val = x.mul(val, (x.add(x.mul(x.convert(gg.Value),{1,0}),{1,0})))
svb = x.add(svb, val)
dirt.Value = x.bnumtostr(svb)
HP = config.HP.Value
geodeopen.Value = geodeopen.Value + 1
if x.eq(random2, {1,0}) then
local svb = x.convert(stone.Value)
local val = x.convert(config.amount.Value)
local val = x.mul(val, (x.add(x.mul(x.convert(gg.Value),{1,0}),{1,0})))
svb = x.add(svb, val)
stone.Value = x.bnumtostr(svb)
HP = config.HP.Value
geodeopen.Value = geodeopen.Value + 1
if x.eq(random3, {1,0}) then
local svb = x.convert(diamond.Value)
local val = x.convert(config.amount.Value)
local val = x.mul(val, (x.add(x.mul(x.convert(gg.Value),{1,0}),{1,0})))
svb = x.add(svb, val)
diamond.Value = x.bnumtostr(svb)
HP = config.HP.Value
geodeopen.Value = geodeopen.Value + 1
end
end
end
end)
end
end
end
end)
local svb = x.convert(config.cost.Value)
local sv = x.convert(config.amount.Value)
script.Parent.part.BillboardGui.cost.Text = "Req: "..x.short(svb).." Rebirth"-- just change the stuff between the ""
script.Parent.part.BillboardGui.amount.Text = x.short(sv).." Basic Geode "