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

There are no errors yet the kill for cash script does not work?

Asked by 3 years ago

I made a script that, when you kill a dummy you get cash. The leaderstats works perfectly but no cash is being added.

Kill for cash script:

local humanoid = script.Parent.Humanoid

function Dead()
    local tag = humanoid:FindFirstChild("creator")
    if tag ~= nil then
        if tag.Value ~= nil then
            local stats = tag.Value:FindFirstChild("leaderstats")
            if stats ~= nil then
                stats.Kills.Value = stats.Cash.Value + 1
                wait(0.1)
                script:Remove()
            end

        end
    end
end

humanoid.Died:Connect(Dead())

Leaderstats script:

local cashstore = game:GetService("DataStoreService"):GetDataStore("CashStore")

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "leaderstats"

    local kills = Instance.new("IntValue", stats)
    kills.Name = "Kills"
    kills.Value = 0

    local cash = Instance.new("IntValue", stats)
    cash.Name = "Cash"

    local val = cashstore:GetAsync(player.UserId)
    if val then
        cash.Value = val
    else
        cash.Value = 0
    end 
end)

1 answer

Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
3 years ago
local humanoid = script.Parent.Humanoid

function Dead()
    local tag = humanoid:FindFirstChild("creator")
    if tag ~= nil then
        if tag.Value ~= nil then
            local stats = game.Players[tag.Value]:FindFirstChild("leaderstats")
            if stats ~= nil then
                stats.Kills.Value = stats.Cash.Value + 1
                wait(0.1)
                script:Remove()
            end

        end
    end
end

humanoid.Died:Connect(Dead())

Should work.

Ad

Answer this question