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

How To Combine Strength, Endurance, Psychic Leader Stats Into One Leader Stat "Total Power"?

Asked by 4 years ago

I Basically Want To Know How To Combine Stats Into One. Here's My Current Code

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

    local Strength = Instance.new("IntValue", leaderstats)
    Strength.Name = "Strength"

    local Endurance = Instance.new("IntValue", leaderstats)
    Endurance.Name = "Endurance"

    local Psychic = Instance.new("IntValue", leaderstats)
    Psychic.Name = "Psychic"

    local TotalPower = Instance.new("IntValue", leaderstats)
    TotalPower.Name = "Total Power"
    TotalPower.Value = Strength.Value + Endurance.Value + Psychic.Value
0
In the part of the script you are showing, you're adding them together in totalpower to combine them. I assume that would work, so what's the issue? Befogs 113 — 4y
0
when i launch the game, it doesnt seem to show my total power but instead say zero Proskillez342 9 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

This code looks fine however, you need to refresh the "Total Power" Value each time one of the other stats increase. For example


game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder", plr) leaderstats.Name = "leaderstats" local Strength = Instance.new("IntValue", leaderstats) Strength.Name = "Strength" local Endurance = Instance.new("IntValue", leaderstats) Endurance.Name = "Endurance" local Psychic = Instance.new("IntValue", leaderstats) Psychic.Name = "Psychic" local TotalPower = Instance.new("IntValue", leaderstats) TotalPower.Name = "Total Power" TotalPower.Value = Strength.Value + Endurance.Value + Psychic.Value function refresh() --we make a new function so it's easier to refresh later TotalPower.Value = Strength.Value + Endurance.Value + Psychic.Value end for index,value in ipairs(leaderstats:GetChildren()) do --for every stat do value.Changed:Connect(function() --whenever the stat changes we want to refresh the total power value refresh() end) end end)

(This code may not work, I haven't tested it.)

Ad

Answer this question