local ReplicatedStorage = game:GetService("ReplicatedStorage") local KillXPGainEvent = ReplicatedStorage:WaitForChild("KillXPGain") local Humanoid = script.Parent:WaitForChild("Humanoid") Humanoid.Died:Connect(function() print("Player killed a zombie!) KillXPGainEvent:FireServer() end)
I'm making a zombies game and I'm trying to use a localscript to to fire a server event when a zombie is killed. I have fired the event trying other methods and it works but when I kill the zombie it doesn't register, I tried getting it to print after killing the zombie to troubleshoot but it won't print.
I'm pretty new to this so forgive me if i missed something trivial.
local ReplicatedStorage = game:GetService("ReplicatedStorage") local KillXPGainEvent = ReplicatedStorage:WaitForChild("KillXPGain") local XPPerKill = 5 KillXPGainEvent.OnServerEvent:Connect(function(Player) local leaderstats = Player:WaitForChild("leaderstats") print("FoundLeaderstats") local EXP = leaderstats:WaitForChild("EXP") print("FoundEXP") EXP.Value = EXP.Value + XPPerKill end)
This is the server script.