I want to achieve a working objective system.
I have let’s say 10 bricks. Each time I press one I want the gui to go from 0/10 to 1/10, if I press another it goes to 2/10 and goes on. If it reaches 10/10 i want the gui to dissappear. I saw a video and made this but it doesn’t work.
ignore the:
Local brick = game.Workspace.brick
this is the script that takes the values number and shows it to the gui:
here is the script to add +1 to the value if the brick is clicked:
here is the value:
The first problem is that when i click the brick the value doesn’t go up and second even if i change the value manually the gui still shows 1 instead of 2.
Your problem isn’t that the code isn’t working, it’s that you’re changing the value the wrong way. Have a look at PlayerGui.
So, what I would recommend instead of having the Bricks IntValue inside of the TextLabel is putting it inside of ReplicatedStorage.
Then, put a LocalScript inside of the TextLabel that says this:
local Bricks = game.ReplicatedStorage.Bricks
Bricks:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = "Bricks "..Bricks.Value.."/"
if Bricks.Value == 10 then
script.Parent.Parent.Visible = false
end
end)
Then just change your ClickDetector script to change the value inside of ReplicatedStorage.
Another option would be to use a RemoteEvent and use FireAllClients, you can check that out too if you’re interested.
Let me know if that fixes your problem!
When i clicked the brick it didn’t change the value but when i changed it manually it dissapeared( because i changed:
if Bricks.Value == 10 then
to
if Bricks.Value == 2 then
to test it.
Also the TextLabel says “Label” instead of “Bricks …/10”
Inside my brick script:
local cd = game.Workspace.brick.ClickDetector
local DestroyPart = game.Workspace.brick
local val = game.ReplicatedStorage.Bricks.Value
cd.MouseClick:Connect(function()
val += 1
DestroyPart:Destroy()
end)
Alright, try this code for the localscript:
local Bricks = game.ReplicatedStorage.Bricks
script.Parent.Text = "Bricks "..Bricks.Value.."/10"
Bricks:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = "Bricks "..Bricks.Value.."/10"
if Bricks.Value == 10 then
script.Parent.Parent.Visible = false
end
end)
And this for the ClickDetector:
local cd = script.Parent
local DestroyPart = script.Parent.Parent
local val = game.ReplicatedStorage.Bricks
cd.MouseClick:Connect(function()
val.Value += 1
DestroyPart:Destroy()
end)
Yes!!! It worked. Thank you so much!! I subscribed to you.
Also changed IntValue with NumberValue
1 Like
No problem, glad that fixed it!