BoolValue.Changed broken

When using BoolValue.Changed, the code underneath does not run but everything before the .Changed runs so I know everything should work.

I’ve also tried GetPropertyChangedSignal but that didn’t work as well.
I’ve checked and it changes the value on the server.

Code:

	script.Parent.Changed:Connect(function()
		print("changed")
		geardata:SetAsync(plr.UserId, script.Parent.Value)
	end)

And yes, the value is changing AFTER all that stuff. It is inside a PlayerAdded function.

Is this code inside another function?
If so then it would only recognize .Changed if it was changing at that exact moment the section of code is running.

Can you include a bit more context? like how are you changing the value, and what other things are going on within the script where the connection is made?

Did you try using :GetPropertyChangedSignal() ?

1 Like

Try this

	script.Parent:GetPropertyChangedSignal("Value"):Connect(function()
		print("changed")
		geardata:SetAsync(plr.UserId, script.Parent.Value)
	end)
1 Like

wrap it up inside a coroutine function:

coroutine.wrap(function()
	script.Parent.Changed:Connect(function()
		print("changed")
		geardata:SetAsync(plr.UserId, script.Parent.Value)
	end)
end)()

Here’s the full code.
Sorry I was sleeping btw.
The value is changed to true when a player buys something.

local service = game:GetService("DataStoreService")

local geardata = service:GetDataStore("q35t3626notherealone")


game.Players.PlayerAdded:Connect(function(plr)
	
	script.Parent.Value = geardata:GetAsync(plr.UserId) or false
	print(script.Parent.Value)
	print("gotten async")
	
	task.wait()
	
	if script.Parent.Value == true then
		plr.PlayerGui:WaitForChild("Shop").Items.Placeholder.Purchased.Purchase:Fire()
		print("purchased")
	end

		script.Parent.Changed:Connect(function()
			print("changed")
			geardata:SetAsync(plr.UserId, script.Parent.Value)
		end)
	
end)

Still didn’t work. charssss

As I stated in the post, I tried that exact thing.

coroutine.wrap(function()
	script.Parent:GetPropertyChangedSignal("Value"):Connect(function()
		print("changed")
		geardata:SetAsync(plr.UserId, script.Parent.Value)
	end)
end)()

If this did not work, then simply just put the function at the end.

Ended up fixing it myself. Thanks for the help though, everyone.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.