local Player = game.Players.LocalPlayer local Stats = Player:WaitForChild("leaderstats") local Figure = script.Parent local Humanoid = Figure:WaitForChild("Humanoid") local EXP = Stats:WaitForChild("EXP") while Humanoid.Health < 1 do EXP.Value == EXP.Value + 1 Figure:Destroy() end
I wanna have this make it so when the zombie dies, it gives the player EXP, I can't figure out what is wrong with this script, and it showsup as an error in line 8, under EXP.Value. Does anyone know why? (This is a LocalScript)
To do this, you will need a ServerScript inside of the NPC that will die.
To start off, you would want to check if the NPC died and then increase everyone's exp by a certain amount that you would like.
ServerScript inside of the NPC
local hum = script.Parent:WaitForChild("Humanoid") hum.Died:Connect(function() local EXP_AMOUNT = 100 --// Change this to the amount of EXP you want them to receive for _,player in pairs(game:GetService("Players"):GetPlayers()) do local exp = player:WaitForChild("leaderstats"):FindFirstChild("EXP") exp.Value = exp.Value + EXP_AMOUNT end end)
This is a ServerScript so it will server cross, if this was in a LocalScript it would only happen on the client side, not the server side. So, the EXP wouldn't save in the data save.
Hope this helped! If it worked, let me know by selecting this as the answer, if it didn't comment down below what went wrong and how I can help.
~killerbrenden
I can help you with this in person. Shoot me a request and I will accept it @TheLastHabanero. This is hard to explain in writing so I will help you with your game personally.
Best
-TheLastHabanero