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

How to increase 2 IntValues from leaderboard at once?

Asked by
n_ubo 29
5 years ago
Edited 5 years ago

heres what i want:

local Players = game.Players

local Template = Instance.new 'BoolValue'
Template.Name = 'leaderstats'

Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Deaths"
Instance.new('IntValue', Template).Name = "Bux"


Players.PlayerAdded:Connect(function(Player)
    wait(1)
    local Stats = Template:Clone()
    Stats.Parent = Player
    local Deaths = Stats.Deaths
    Player.CharacterAdded:connect(function(Character)
        Deaths.Value = Deaths.Value + 1
        local Humanoid = Character:FindFirstChild "Humanoid"
        if Humanoid then
            Humanoid.Died:Connect(function()
                for i, Child in pairs(Humanoid:GetChildren()) do
                    if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
                        local Killer = Child.Value
                        if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills"  then -- but also "Bux" here, i can only grab "Kills" but not both.
                            local Kills = Killer.leaderstats.Kills
                            local Bux = Killer.leaderstats.Bux
                            Kills.Value = Kills.Value + 1
                            Bux.Value = Bux.Value + math.Random(15,25)

                        end
                        return
                    end
                end
            end)
        end
    end)
end)

what i try to do is increase 2 int values from the leaderboard when a kill is made but is there another instance than findfirstshild so that i can increase both instead of 1?

0
"Template" is never given a parent. Therefore, Template and its descendants remain in thin air. DeceptiveCaster 3761 — 5y
0
the script still works fine to me n_ubo 29 — 5y
0
only bux value won't increase after kill event n_ubo 29 — 5y

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
5 years ago

the r in math.random isn't capitalized

0
-1 for posting incomplete answer, this fits as a comment therefore it belongs as one. Additionally, please remove the unjust downvote you have given to my answer here; https://scriptinghelpers.org/questions/90264/to-many-upvalues-error-how-to-simplify programmerHere 371 — 5y
Ad

Answer this question