Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

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?

0

when i launch the game, it doesnt seem to show my total power but instead say zero

1 answer

✓ Accepted answer

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.)

This discussion is preserved as it was. New answers, comments, and votes are closed.