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

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by
PolyyDev 214 Moderation Voter
6 years ago

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.

Ad

Answer this question