Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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)

0
Does your weapon put Creator value inside NPC after attacking it? Sabailuridze 126 — 2y

1 answer

Log in to vote
0
Answered by
ryanzhzh 128
2 years ago

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)
Ad

Answer this question