Using values to increas a value

I want to have multiple BoolValues inside of a player increase the number of a leaderstat when a BoolValue becomes true.

Example:
(BoolValue1 = true
BoolValue2 = false
LeaderstatValue = 1

BoolValue1 = true
BoolValue2 = true
LeaderstatValue = 2

I’m really uncertain what I did wrong, but the value does not change when I load into the game with my BoolValue checked as true

I have looked for and tried various solutions but nothing has given me results.

If anyone can help me with this, I would appreciate it a lot! Thanks!

if script.Parent.Value == true then
		script.Parent.Parent.Parent.leaderstats.CDs.Value = script.Parent.Parent.Parent.leaderstats.CDs.Value + 1
	end

Well I’m not too sure because I don’t know if this is your entire script, or the exact locations of these values, etc. However, unless you’re using a changed event to detect when the value becomes true, it is only going to run when the game first starts, and not once a change has been made.

Try seeing if that helps, and if it doesn’t please post the rest of your code if there is more too it, and the locations of these items in the explorer

Try using a changed event

script.Parent.Value.Changed:Connect(function()
if script.Parent.Value == true then --or you use a function variable
script.Parent.Parent.Parent.leaderstats.CDs.Value += 1 --increases CD value
else wait()
end
end)

Also, Is this a LocalScript or a serverscript, and where is it located? Is it the full script? I’d like you to let me know.

If it is a LocalScript, consider changing it because a LocalScript only makes changes locally

That was the full script besides the fact that I had a loop to start
Capture444
Here’s the location of things, but with a script inside of the Value (Forgot to crop it in) Also it is a regular script.

I just tried to make it own my own, for me it works. Are you sure that it is located in the player?

1 Like

Yes, just edited the picture for a better view

The script does not seem to be detected when the value updates, any suggestions?

Are you using a script to move the folders into the player? That’s what I did.
If it still doesn’t work, make sure to check for the value and names everything twice, else i wouldn’t know because for me, it works perfectly fine.

Scripts i used:
Move Folders (make sure that it’s all in a model, folder, or have the same parent.)

local plr = script.Parent.Parent.Parent --localplayer

script.Parent.CDs.Parent = plr --folder CDs

script.Parent.leaderstats.Parent = plr --folder leaderstats

Value

script.Parent.Value.Changed:Connect(function()
if script.Parent.Value == true then --or you use a function variable
script.Parent.Parent.Parent.leaderstats.CDs.Value += 1 --increases CD value
else wait()
end
end)

If you’re using a serverscript that uses Instance() then you would have to approach it differently
unknown
Located in StarterGui, StarterPack, or StarterPlayer.

1 Like

Will do, thanks for your help!

Actually, the changed event I mentioned above is a lot more efficient than a loop like this. The event will only fire when the bool value has been changed, not constantly while the game runs, and becoming dependent on this method can cause lag within your game. Firing on change is a much better and smoother method to be getting a change.

2 Likes

Yeah, that’s true, I wasn’t thinking about that because i absolutely suck in functions, thanks for the reminder.

Edit: I have edited the scripts previously sent with the Value.Changed function.