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...
01 | num = 0 |
02 | function T(hit) |
03 | name = hit.Parent |
04 | players = game:GetService( "Players" ) |
05 | player = players:findFirstChild(name.Name) |
06 | if player.leaderstats.Gems.Value< = num then |
07 | local gems = player.leaderstats.Gems |
08 | gems.Value = gems.Value+ 1 |
09 | end |
10 | end |
11 | 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:
1 | adarksDictionary = { A = true , B = true , C = true , D = true } |
If you have F
and E
, but not B
, yours would look like this:
1 | dsboy 55 sDictionary = { A = true , C = true , D = true , E = true , F = true } |
To get the total star count, just walk the table:
1 | local total = 0 |
2 | for _, v in ipairs (dsboy 55 sDictionary) do |
3 | if v then --in case a star gets saved as false (which shouldn't happen, but I digress) |
4 | total = total + 1 |
5 | end |
6 | end |
7 | print ( "dsboy55 has collected " .. total .. " Stars!" ) |