How CAN I make this system work?

Hello guys, my name is spideyalvaro999
So I wanted to make this system work, but my scripting knowledges doesn’t know how. So the system is like a minigame, there are 5 objects around the map and when you click that object, the Text from a TextLabel on a ScreenGui changes from 0/5 to 1/5. The problem where is that I dont want to stablish the objects an orther. For example, we have object1, object2, object3, object4 and object5.
You haven’t clicked any object yet so your TextLabel is (“0/5”). Suddenly, you find object number 4, but your TextLabel doen’t change from (“0/5”) to (“4/5”), but it change from (“0/5”) to (“1/5”). Also the problem I had is that I wanted to make it on the Client and not on the Server, because as you are thinking, everyone should have their own counter. So this is all the explanation, I had try a lo of things on the past but non of them worked, so I hope that your help help me.
Thanks for spending your time reading and awnsering my post
Have a good day
Spideyalvaro999

1 Like

i suggest making a table which contains something like

local Table = {Object1, Object2, ...}
local Count = {false, false, false, false, false}

local function Update()
    for k, v in pairs(Count) do -- iterates over the table Count, with k = 1,2,... and
                                             -- v = true/false, true/false...
        local Variable = 0
        if v == true then
            Variable = Variable + 1
        end
    end
    TextLabel.Text = tostring(Variable) .. "/5"
end

for k, v in pairs(Table) do -- iterates over Table, with k = 1,2,... and v = Object1,
                                               --Object2,...
    v.ClickDetector.MouseClick:Connect(function()
        Count[k] = true
        Update()
    end
end

something like that
this is a very simple way to do it, which you should be able to understand
not sure if it would work or not, it’s 3am and i’m too lazy to open up studio(sorry)

2 Likes

Yeah I will try, Thanks for the scripting, seriously
But this scripting I introduce it on a local script or on a normal script?
and I put it on the screen GUI or where?

usually just a LocalScript, wherever you want as long as it’s accessible by the client
you may also want to add a RemoteEvent that sends signals to the server for checking (anti-hacking)
i suggest combining several scripts into one, since 10 scripts with only a few lines are generally a bad sign

I did this, but I dont know if theres something missing that doesnt work when clicking

--/Variables/--
local mate = workspace:FindFirstChild("Mate")

local pez = workspace:FindFirstChild("Pez")

local reproductor = workspace:FindFirstChild("Reproductor")

local sensei = workspace:FindFirstChild("Sensei")

local sombrero = workspace:FindFirstChild("Sombrero")

local Table = {	mate,pez,reproductor,sensei,sombrero}

local Count = {false, false, false, false, false}

local TextLabel = game.StarterGui:FindFirstChild("ScreenGui").TextLabel

local replicateStorage = game:FindFirstChild("ReplicatedStorage")

local remoteEvent = replicateStorage:FindFirstChild("MiniGame")
--/Coding/--
local function Update()
	local Variable = 0
	    for k, v in pairs(Count) do
        if v == true then
            Variable = Variable + 1
        end
	    end
    TextLabel.Text = tostring(Variable) .. "/5"
end

for k, v in pairs(Table) do      
v.ClickDetector.MouseClick:Connect(function()
Count[k] = true
Update()
end) 
	end

By the way I put the local remote event but I didnt use it because firt I want to see if it works with outthe anti hacking way

1 Like

the only thing i could find is this line:

local TextLabel = game.StarterGui:FindFirstChild("ScreenGui").TextLabel

you should do something like

local TextLabel = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("ScreenGui")

you need to look for the ScreenGui within the local player, and not from the game
the player only sees ui that is in Player.PlayerGui

at the end, should I put .TextLabel or is not neccesary?

it is necessary
oh yeah forgot that, sorry

YESS IT WORKED! THANK YOU VERY MUCH!
The error was on the TextLabel Variable. I will Include this right now
Thanks! :smiley:

And one doubt
How could I do too make a data store service for saving the text?

you’d have to send the text to the server (via a RemoteEvent), then save it with DataStore:SetAsync()/UpdateAsync() regularly/when the player leaves
you can read about datastore here:
https://developer.roblox.com/en-us/api-reference/function/GlobalDataStore/SetAsync
https://developer.roblox.com/en-us/articles/Data-store

so I write on the local script the remote event line ( is RemoteEvent:FireServer()?) and on the server script the data store line right?