No matter what I try “Spared!” continues to run at least 5 times after “Spare Triggered” has already been activated once.
I don’t understand how if the function is only triggering once yet the player continues to lose gold multiple times; is there something I’m missing here? I’m stumped.
Script (Server)
game.ReplicatedStorage.Requests.Spared.OnServerEvent:connect(function(pl)
print("Spared Triggered")
local dPlayer = pl
local dFolder = dPlayer and game.ServerStorage.PlayerData:FindFirstChild(dPlayer.Name)
local ch = dPlayer.Character
local dhum = ch:FindFirstChild("Humanoid")
local dfx = dhum:FindFirstChild("Effects")
local dsp = dhum:FindFirstChild("Spare")
for _,v in pairs(dfx:children()) do
if v.Name == "InCombat" then
v:Destroy()
end
local Spared = Instance.new("BoolValue",dfx)
Spared.Name = "Spared"
game.Debris:AddItem(Spared,15)
local iFrame = Instance.new("BoolValue",dfx)
iFrame.Name = "FullDefence"
game.Debris:AddItem(iFrame,15)
local toolinuse = Instance.new("BoolValue",dfx)
toolinuse.Name = "ToolInUse"
game.Debris:AddItem(toolinuse,15)
dsp.Value = dsp.MinValue
print("Spared! (NPC)")
local takeGold = dFolder.Gold.Value*0.2
dFolder.Gold.Value = dFolder.Gold.Value - takeGold
spawn(function()
game.ServerStorage.Requests.SaveData:Invoke(dPlayer,dFolder)
end)
end
end)
Script (Local)
game:service("RunService").RenderStepped:connect(function()
if dead then return end
if SP.Value == SP.MaxValue then
game.ReplicatedStorage.Requests.Spared:FireServer(Player)
SP.Value = SP.MinValue
end
game.ReplicatedStorage.Requests.Spared.OnServerEvent:connect(function(pl)
print("Spared Triggered")
local dPlayer = pl
local dFolder = dPlayer and game.ServerStorage.PlayerData:FindFirstChild(dPlayer.Name)
local ch = dPlayer.Character
local dhum = ch:FindFirstChild("Humanoid")
local dfx = dhum:FindFirstChild("Effects")
local dsp = dhum:FindFirstChild("Spare")
for _,v in pairs(dfx:children()) do
if v.Name == "InCombat" then
v:Destroy()
end
end
local Spared = Instance.new("BoolValue",dfx)
Spared.Name = "Spared"
game.Debris:AddItem(Spared,15)
local iFrame = Instance.new("BoolValue",dfx)
iFrame.Name = "FullDefence"
game.Debris:AddItem(iFrame,15)
local toolinuse = Instance.new("BoolValue",dfx)
toolinuse.Name = "ToolInUse"
game.Debris:AddItem(toolinuse,15)
dsp.Value = dsp.MinValue
print("Spared! (NPC)")
local takeGold = dFolder.Gold.Value*0.2
dFolder.Gold.Value = dFolder.Gold.Value - takeGold
spawn(function()
game.ServerStorage.Requests.SaveData:Invoke(dPlayer,dFolder)
end)
end)