Bindable Event Not Updating Int Value?

Hey Again!

So I’m working on a game where I am using a proximity prompt to fire a bindable event in order to change an Int Value in Server Storage. Problem is, well… it’s not updating to the new Value. Here are the scripts.

the bindable is located in game.ServerStorage.Values.CollectedNotebooks

ProximityPrompt Script:
image

Handler Script:
image

I have even tried checking for the value every second through a script in Workspace:

local CollectedNotebooks = game.ServerStorage.Values.CollectedNotebooks.Value
while wait(1) do
print(CollectedNotebooks)
end

But this happens:
image

Any help would be greatly appreciated! :smile:

Assuming CollectedNotebooks is an IntValue instance in the ServerStorage, I think you’ll have to use CollectedNotebooks.Value.

You are only changing the CollectedNotebooks variable, not the value.

For future reference, it’s a good idea to share the code using ``` tick marks before and after your code to format it, so we can copy, test, and edit.

local CollectedNotebooks = game.ServerStorage.Values.CollectedNotebooks
...
CollectedNotebooks.Value += 1

You cant set the value of an IntValue when you set a variable to the value.
local CollectedNotebooks = game.ServerStorage.Values.CollectedNotebooks.Value
Will just be an integer, nothing else.
So the value is not updated in the IntValue.
Update the IntValue’s Value

I dont understand guys…

because when i need to change the int value’s value i do what you said already in the screenshots. I write
local CollectedNotebooks = game.ServerStorage.Values.CollectedNotebooks.Value
but it does not work?

Because the .Value property returns an integer… this integer is a copy of the IntValue’s value.

So the variable is an integer. Only way to modify an IntValue is to set the .Value property.

local CN = CollectedNotebooks.Value -- this sets CN to the number
CN = CN + 1 -- this adds 1 to CN, but doesn't do anything to CollectedNotebooks.Value
...
local CN = CollectedNotebooks -- this sets CN to CollectedNotebooks
CN.Value = CN.Value + 1 -- this adds 1 to CN.Value

Umm fix the second example, they are both the same variable in terms of what they are setto

1 Like

I get this now: image

Code Now:

local CollectedNotebooks = game.ServerStorage.Values.CollectedNotebooks

bindable.Event:Connect(function()
	local CN = CollectedNotebooks
	CN.Value = CN.Value + 1
	print(CollectedNotebooks)
	if CollectedNotebooks == 10 then
		-- Game Over
	end
end)```

I honestly thought it would be

local val = game.ServerStorage.Values.CollectedNotebooks.Value -- gets value
val = val + 1 -- sets value

Just change these lines

print(CollectedNotebooks.Value)
if CollectedNotebooks.Value == 10 then

Let me know if you need more explanation on why this happens the way it does, but I can get a little long-winded when I explain things.

2 Likes

Thanks! Such a simple task took so long, sorry for the trouble everyone!

Wrote this up for you, to help explain:

local int = workspace.Value --> Create a variable to the integer object

while true do
	int.Value = int.Value + 1 --> The value of int is being changed, not the variable itself
	print(int.Value)
	wait(1)
	int.Value = 0	--> Reset for test
	break
end

local int = workspace.Value.Value --> Becomes a reference to the integer value, not the object


while true do
	int = int + 1	-- > Updates the variable 
	
	print(int)		--> Prints 1
	print(workspace.Value.Value) --> Prints 0 as the object has not been changed
	wait(1)
	break
end

local int = workspace.Value --> Create a variable to the integer object

print(int.Parent) --> Prints Workspace

local int = workspace.Value.Value --> Create a variable to the integer itself

while true do
	if int == 10 then
		break
	else
		int = int + 1
	end
end

print(int.Parent) --> Throws error, since the variable is an integer not a reference to the object.
print("Success")
2 Likes