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

What is the best way to have a variable that everyone has to alter individually?

Asked by 3 years ago
Edited 3 years ago

So I have these coins, right? They act as collectibles that players can get by touching, and once they do, it becomes transparent to signify that they already got that coin. The coins remain nontransparent until you collect it yourself and when you do, it is added to the coin count inside of the coin count GUI.

However, there is one problem with this script. It's that the boolVals for each coin that changes for everyone once one player accesses it. This makes it so a player who comes in after a previously collected coin and collects it will add to their coin count by 15+ because there is no denounce that says they can't collect it again.

I expect this sort of thing, but I need to find an easy solution for this problem. Right now, I am thinking about creating 7 boolean instances in the players so that everyone has their own boolVal they can alter. However, I feel as if this is a very messy way to go about this, and I'd like to know if there is anything better that I can do. If so, please let me know in detail as I am not very experienced in coding.

  • FilteringEnabled is on
  • the script is a local script inside of StarterGui
local coinTrack1 = true
local coinTrack2 = true
local coinTrack3 = true
local coinTrack4 = true
local coinTrack5 = true
local coinTrack6 = true
local coinTrack7 = true
local coinNum
local CoinTrackerLabel = game.StarterGui.CoinTracker.Frame.TextLabel.Text
if coinNum == nil then
    coinNum = 0
end
game.StarterGui.CoinTracker.Frame.TextLabel.Text = "Coin "..coinNum.."/7"
game.Workspace.RedCoin1.Touched:Connect(function(hit)
    if coinTrack1 == true then
        if hit.Parent:WaitForChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if coinNum == nil then
                coinNum = 0
            end
            coinNum = coinNum + 1
            player.PlayerGui.CoinTracker.Frame.TextLabel.Text =  "Coins "..coinNum.."/7"
            game.Workspace.RedCoin1.Transparency = .85

            coinTrack1 = false
            return coinNum


        end
    end

end)
-- Then there is a function identical to the above one for each Coin

Answer this question