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

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

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.

2 comments

0

Why don't you use GetPlayerFromCharacter?

0

I like to mix things up. Actually, it's just instinct.

1 answer

✓ Accepted answer

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!")

2 comments

0

How would that add to a number value in leaderstats, though?

0

Walk the table. I'll add an example code to the end.

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