Update IntValue automatically

Hi all, I’m new to scripting so sorry if it’s a dumb question.

I have an IntValue that I need to update automatically and non-linearly. It needs to be updated in four different scripts tied to four different click detectors.

I thought I could do it like this:

Marker = script.Parent.Parent.Parent.Marker1.Marker1
Collected = game.Workspace.EvidenceMarked.Value
ClickDetector=script.Parent
ClickDetector.MouseClick:Connect(function()
	Marker.Transparency = 0
	Marker.CanCollide = true
	Collected = Collected + 1
	print(Collected)
end)

But when it prints the value to the output panel, it always prints 1. Is there a way to accomplish this? Do I need to be using a NumberValue instead or is that just for if my value has decimal places (it doesn’t).

Marker = script.Parent.Parent.Parent.Marker1.Marker1
Collected = game.Workspace.EvidenceMarked.Value --if the EvidenceMarked is 0 then only 0 is saved in Collected variable locally in a script
ClickDetector=script.Parent
ClickDetector.MouseClick:Connect(function()
	Marker.Transparency = 0
	Marker.CanCollide = true
	Collected = Collected + 1 --it only changes in script and not the actual value
	print(Collected)
end)

this is how it works

Marker = script.Parent.Parent.Parent.Marker1.Marker1
Collected = game.Workspace.EvidenceMarked --now the actual instance is saved in collected variable
ClickDetector=script.Parent
ClickDetector.MouseClick:Connect(function()
	Marker.Transparency = 0
	Marker.CanCollide = true
	Collected.Value = Collected.Value + 1 --now its value is changed
	print(Collected)
end)
1 Like

Yeah, it works now. It just hit me that declaring the value instead of the instance gives each script the initial 0 value at start and they worked with that. Thanks for your help!

1 Like