generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Sum of a list of values

Previous Thread :: Next Thread 
compy111 is not online. compy111
Joined: 02 Apr 2009
Total Posts: 583
29 Mar 2014 05:29 AM
I am working on an RPG and it has multiple skills you will have to improve.
But as in every game you may have multiple skills but still you need a total level to have an idea of who is how far in the game.
In the script that writes all the player's levels into a GUI I used lists and then it used the names of the skills to find them. This makes it easy for me to add more skills later. I just have to add a GUI text, add it to the save data script and add it to the list.

But I have no idea how I could get the numbers together in one formula.
I usually use a for function, but this only takes one skill at a time.
I could do:
combatlevels[1] + combatlevels[2] + combatlevels[3] + combatlevels[4]

But if for example there would be 1000 skills it would take hours to make it, anyone knows how to do it?



My current working script where the part has to be added:


player = script.Parent.Parent.Parent.Parent
combatlevels = {"Ranged","Health","Strength","Defense"}

while true do
wait()
for i = 1 , #combatlevels do
stats = player:FindFirstChild("Stats")
if stats then
level = player.Stats.Combat:FindFirstChild(combatlevels[i])
print(level.Name)
GUI = script.Parent:FindFirstChild(combatlevels[i])
GUI.Text = combatlevels[i]..": "..level.Value
end
end
end


Thanks for your help
Report Abuse
compy111 is not online. compy111
Joined: 02 Apr 2009
Total Posts: 583
29 Mar 2014 06:08 AM
My own replies to others make my post go back to the bottom of the list, so here it goes up again :-)
Report Abuse
MarioKartAddict is not online. MarioKartAddict
Joined: 11 Nov 2009
Total Posts: 42774
29 Mar 2014 07:32 AM
values = {1, 3, 7, 8, 2}
total = 0

for i = 1, #values do
total = total + values[i]
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image