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

currency system, im making it so that you kill a zombie and it give u money pls help script no work?

Asked by
wswswff 39
2 years ago
game.Players.PlayerAdded:Connect(leaderboardSetup)
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    local cash = Instance.new("NumberValue")
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = leaderstats

    player.CharacterAdded:Connect(function(Character)
        Character.Humanoid.Died:Connect(function(Died)
            local creator = Character.Humanoid:FindFirstChild("creator")
            local leaderstats = creator.Value:FindFirstChild("leaderstats")
            if creator ~= nil and creator.Value ~= nil then
                leaderstats.Cash.Value = leaderstats.Cash.Value + 10
            end
        end)
    end)
end)










end)

idk y if u know pls type why and the fixed script ill accept the answer if its correct i check every hour

0
is this script inside of the zombie? jedistuff2 89 — 2y
0
what does leaderboardSetup do? loowa_yawn 383 — 2y
0
Script is in serverscriptservice wswswff 39 — 2y
0
with your current script, you're checking when the player dies jedistuff2 89 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

In this script, you are looking for a child of a value, which wont exist. Use bindableevents to fire between scripts

--Script in the tool (add this in with the gun, Hit = raycast.Instance or whatever you use
local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) or script.Parent.Parent.Parent

local Tagged = Instance.new("ObjectValue")
Tagged.Name = "creator"
Tagged.Value = Player
Tagged.Parent = Hit.Parent.Humanoid
game.Debris:AddItem(Tagged, 2)

--Script inside the zombie
local Character = script.Parent
Character.Humanoid.Died:Connect(function()
    if Character.Humanoid:FindFirstChild("creator") then
        local Player = Character.Humanoid.creator.Value
                local Leaderstats = Player.leaderstats
                Leaderstats.Cash.Value += 10
            end
end
Ad

Answer this question