Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make it when player kill an npc they get cash?

I was watching other videos but it did not work my currency is named gold pls help! I put this script in the npc.

local Humanoid = script.Parent.Humanoid function Dead() local tag = Humanoid:FindFirstChild("creator") if tag ~= nil then if tag.Value ~= nil then local leaderstats = tag.Value:FindFirstChild("leaderstats") if leaderstats ~= nil then leaderstats.Cash.Value = leaderstats.Cash.Value +10 wait(0.1) script:Remove() end end end end Humanoid.Died:Connect(Dead)

1 comment

0

Does your weapon put Creator value inside NPC after attacking it?

1 answer

Basically, the creator tag under the humanoid when they die is a life saver. It gives you who killed the humanoid. On to the topic. It doesn't actually works since it's not replicated to the server, if its in a local script. Also WHY did you do this: leaderstats.Cash it should be leaderstats.Gold! Example code, script runs when a npc dies:

local npc = script.Parent -- script in npc model
local remote = game.ReplicatedStorage.GiveCash
npc.Humanoid.Died:Once(function()
	local tag = npc.Humanoid:WaitForChild("creator")
	tag.leaderstats.Gold.Value += 10
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.