Im trying to make it so that, you touch a brick, it increases the value infinetly +1 everytime you touch it, but when I do, it doesnt increase its value. Here is the script below.
local XP = game.StarterGui.Player_Exp.XP_Num.Val.Value
script.Parent.Touched:Connect(function()
XP = XP + 1
script.Parent.BrickColor = BrickColor.new(255, 255, 255)
end)
It’s a habit I carry over from other programming languages. In languages like Java, a semicolon is required at the end of every line due to it’s syntax.
It’s a huge difference. StarterGui is what’s given when you join/your character spawns.
You want to do Player.PlayerGui in this case to directly change the value of the gui for per player. You also have to use a little bit of networking (remoteevents/ remote functions) to do this.
I would not recommend throwing that in the ring because it can be easily exploited which this user shouldn’t have to deal with in that simple of a way. I would, instead, create a number value for every player who joined, storing it in the server storage (or just using a table), and then updating the XP there.
You are changing the value outside of the main event.
what you need to do is to change the value everytime it gets touched;
local XP = game.StarterGui.Player_Exp.XP_Num.Val.Value
script.Parent.Touched:Connect(function()
XP = XP + 1
game.StarterGui.Player_Exp.XP_Num.Val.Value = XP
script.Parent.BrickColor = BrickColor.new(255, 255, 255)
end)