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

Coins wont add/go away when you click a button?

Asked by 3 years ago

So I have this coin system and Right here is the code that gives the coins to you when a player dies or you kill a player

game.Players.PlayerAdded:connect(function(player)

    local leaderstats = Instance.new("Folder",player)
    leaderstats.Name = "leaderstats"

    local cash = Instance.new("IntValue",leaderstats)
    cash.Name = "Cash"
    cash.Value = 0

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


    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()

            local CreatorTag = character.Humanoid:FindFirstChild("creator")

            if CreatorTag and CreatorTag.Value then

                local stats = CreatorTag.Value:WaitForChild("leaderstats")

                stats["Cash"].Value = stats["Cash"].Value + 20
                stats["Kills"].Value = stats["Kills"].Value + 1         
            end
        end)
    end)
end)

It Is in a regular script btw and I tried doing this under the button(that gives the weapon)

script.parent.MouseButton1Click:connect(function()
leaderstats.Cash.Value = 5
end

also I cut out the code that gives the weapon for the sake of saving space. and it wont work im not sure why? could anyone help

0
also the script under the button is a local script Iownrobloxp 44 — 3y

Answer this question