Have you ever played adventure forward: Star Savior? I want to make a system as they make for their stars. I already have worked out a script. It works...
num=0 function T(hit) name=hit.Parent players=game:GetService("Players") player=players:findFirstChild(name.Name) if player.leaderstats.Gems.Value<=num then local gems=player.leaderstats.Gems gems.Value=gems.Value+1 end end script.Parent.Touched:connect(T)
This will award the gem to the player ONLY if the player has 'num' or less gems.
Here's my problem.
I want the player to collect gems in any order. I can't do temp data, either, because the data saves. I need a way for you to only be able to collect each gem once, but be able to collect them in any order.
Thank you for your time.
What you can do is save a Dictionary of the stars a player has collected.
Say, for instance, I have 4 Stars: A
, B
, C
, and D
. My Dictionary would look like this:
adarksDictionary = {A = true, B = true, C = true, D = true}
If you have F
and E
, but not B
, yours would look like this:
dsboy55sDictionary = {A = true, C = true, D = true, E = true, F = true}
To get the total star count, just walk the table:
local total = 0 for _, v in ipairs(dsboy55sDictionary) do if v then --in case a star gets saved as false (which shouldn't happen, but I digress) total = total + 1 end end print("dsboy55 has collected " .. total .. " Stars!")