-
i’m trying to make it to where the players cash will increase upon the death of the zombie basically but update the cash value that is from the server cause i made a datastore for it and i want the stats that the player gained from killing the zombie to save, and it does work but.
-
the problem is, the script works and everything But it only runs/works once? and then it stops with no error no anything and i can’t figure out what’s wrong? maybe a simple fix i can’t seem to find?
-
i tried changing it to wait for the remote to trigger and or wait for cash to be there and much more i just don’t know what else to do?
server script is
-- Create a RemoteEvent in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:FindFirstChild("ZombieKilled")
local HowMuchCashToReward = math.random(1, 30)
-- Listen for the RemoteEvent
Remote.OnServerEvent:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local cash = leaderstats:FindFirstChild("Cash")
if cash and Remote then
cash.Value = cash.Value + HowMuchCashToReward
end
end)
local script is
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("ZombieKilled")
local zombie = game.Workspace:FindFirstChild("Zombie") -- Wait for the Zombie model to exist
local zombieHumanoid = zombie:WaitForChild("Zombie")
local player = game.Players.LocalPlayer
-- Listen for the zombie's death
zombieHumanoid.Died:Connect(function()
if player then
print("Zombie Died", player)
remote:FireServer(player, zombieHumanoid, remote, zombie)
else
print("Zombie Died, but no associated player found.")
end
end)