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

Kill NPC For Cash Script Will Not Work?

Asked by 3 years ago

Hello. I've got this kill NPC for Money script from the toolbox which should work as I've seen from a tutorial but it will not work at all.

Here is the script:

game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Cash"
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
    local killer = tag.Value
    if killer ~= nil then
        -- Find the killer's leaderstats folder
        local killerStats = killer:FindFirstChild("leaderstats")

        if killerStats ~= nil then
            -- Find the killer's Cash IntValue
            local killerCash = killerStats:FindFirstChild("Cash")

            -- Increase cash as before
            killerCash.Value = killerCash.Value + 10
        end
   end
end
end)
 end)
end)
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Cash = Instance.new("IntValue",leader)
 Cash.Name = "Cash"
 Cash.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Cash.Value)
 Cash.Changed:connect(function()
  ds:SetAsync(player.UserId, Cash.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)

(It also has data saving)

2 answers

Log in to vote
0
Answered by 3 years ago

You can make the script and put it in the NPC instead. For the cash script, keep it the way it was, but take out anything to do with the NPC script.

Put this is the NPC:

local humanoid = script.Parent.Humanoid

local 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:Destroy()
            end
        end
    end
end

humanoid.Died:Connect(dead)


You can clone the NPC from replicated storage to make more of them. If this helped, please accept this answer!!!

0
So I just need to put the script you gave me in the NPC then just make a leaderstats script? LosingLogan 0 — 3y
0
Sadly didn't work. LosingLogan 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

I finally found a script that works.

Answer this question