Ad
Log in to vote
0

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

Asked by 6 days ago
Edited 6 days 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 — 6d

1 answer

Log in to vote
0
Answered by 5 days 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