0
votes

Each brick in my game has a value, and it gets added to leaderstats. But, I want a GUI to show how many BRICKS they have collected. For example, 2 bricks in my game are worth 32 points to be stored in leaderstats. Instead of showing the total, 64, i want it to show the amount of bricks i collected: 2.

Here is the code that collects the bricks and stores them in leaderstats:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.ElectoralVotes.Value = player.leaderstats.ElectoralVotes.Value + 37.5
            script.Sound:Play()
            wait(1)
            script.Parent:Remove()
        end
    end
end) 

I want to keep the leaderstats in the top right, but on the screen i also want it to show the amount of bricks collected. Does anyone know how i could implement this into my game?

1
The brick should have 2 values, the points stored in it, and the amount of brick models collected as well to clear up what i was saying. The gui would say: 0/14 collected.user14354444

1 Answers

0
votes

make a Main GUi and insert an TextLabel inside it insert Int value and a script and put the MainGUI in The Starter Gui Pack next type the below code in the script if TextLabel:

local my_text_gui = script.Parent.TextLabel
local brick_count = my_gui.IntValue
local function change_value()
     my_text_gui.Text = brick_count.Value
     
brick_count:GetPropertyChangedSignal("Value"):Connect(change_value())

Then change the touch detection script and add a value adding code given bellow(works only when the touch detection script is not a local script)

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.ElectoralVotes.Value = player.leaderstats.ElectoralVotes.Value + 37.5
            hit.Parent.PlayerGui.Your_Brick_Counter_GUI.IntValue = hit.Parent.PlayerGui.Your_Brick_Counter_GUI.IntValue + 1
            script.Sound:Play()
            wait(1)
            script.Parent:Remove()
        end
    end
end)

Thanks!