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

I'm trying to make an adventure game collectible. Can someone help?

Asked by 9 years ago

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.

0
Why don't you use `GetPlayerFromCharacter`? woodengop 1134 — 9y
0
I like to mix things up. Actually, it's just instinct. ChemicalHex 979 — 9y

1 answer

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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!")
0
How would that add to a number value in leaderstats, though? ChemicalHex 979 — 9y
0
Walk the table. I'll add an example code to the end. adark 5487 — 9y
Ad

Answer this question