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

How would I code a "Stars Collected" counter? More info in desc...

I want to code how many stars someone has collected but it needs to follow some guidelines It's like Mario 64 or Roblox's Robot 64 if you've played it

Stars need to be able to be collected in any order

Stars can be collected multiple times but only update the counter once

Stars are updated for only a single person, other people don't get the star

I originally tried making an Array that held true or false values that would turn true when the star is collected, but this made it so only a single person in the server could collect that one star

1 answer

You could make a table that holds the stars collected for each person. So when it it collected, you set another array inside the original array with the key as the players player object, username, userid or anything that can relate back to the player.

For example:

local stars = {}

onCollect:Connect(function()
	local player -- However your going to get your player object

	stars[player] = {} -- Using the player object as an example and creating an empty array.
	
	if not stars[player][star] then -- I don't know how you are going to get your star object
		table.insert(stars[player], star) -- Inserting the star into the players array
	end
end)

Accept if this helped, as that would help me.

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