Issue when changing a value from true to false and vice versa

I’m currently working on a system for a game, where if you change a BoolValue from false to true then a part changes transparency and vice versa.

My issue is is that when I change the BoolValue from false to true nothing really happens, the script doesn’t even print the input I put.

I’ve tried using a loop where it constantly checks if the value has been updated or not, but my studio ended up crashing and the game was very laggy.

Any help would be appreciated

The Script
local Value = workspace.TestValue
local Base = workspace.Door1

Value.Changed:Connect(function(value)
	if value == true then
		Base.Transparency = 0.8
		Base.CanCollide = false
		print("It is true")
	else
		Base.Transparency = 0
		Base.CanCollide = false
		print("It is false")
	end
end)
1 Like

Try this

local Value = workspace.TestValue
local Base = workspace.Door1

Value.Changed:Connect(function()
	if Value.Value == true then
		Base.Transparency = 0.8
		Base.CanCollide = false
		print("It is true")
	else
		Base.Transparency = 0
		Base.CanCollide = false
		print("It is false")
	end
end)
1 Like

Hmm, just tried it but it doesn’t seem to work.

1 Like

I’m not sure about this, but try

local Value = workspace.TestValue
local Base = workspace.Door1

Value.Value.Changed:Connect(function()
	if Value.Value == true then
		Base.Transparency = 0.8
		Base.CanCollide = false
		print("It is true")
	else
		Base.Transparency = 0
		Base.CanCollide = false
		print("It is false")
	end
end)
1 Like

Where is this script located? In ServerScriptSrvc?

1 Like

I just put it in workspace to test out the script

1 Like

Where are you changing the Value first? In the client or in the server? If you change it in the client, then in the server it wouldn’t be the same. You should change the value via server. That could be the reason why it’s not changing and not printing anything.

Your script should work.

1 Like

Does that mean that I have to move the script into ServerScriptService?

No it just means, if ur changing it from localscript, it wont b replicated to server, meaning the change wont happen.

1 Like

You don’t have to move the script anywhere. The only thing you should do is change the value in the server. If you are changing the value using a LocalScript, then it won’t be replicated in the server or in simpler words, it won’t change in the server. It would only change locally or to the player only, and the server, your script specifically, would detect no changes in the value.

If you are changing the value using a LocalScript, then you must use RemoteEvents (Bindable Events and Functions | Roblox Creator Documentation).

Alright, but the script I was currently already using a Script and not a localscript

You use a script to change the value or you use a script to detect the change?

I used a script to detect the change of the value and through workspace I manually changed the boolvalue to true or false.

Thats the issue, im pretty sure u changed value while in client mode. Change it to server for it to replicate.

download

2 Likes

I feel a bit like an idiot now, thank you so much, just quickly made a button which changes the value and it worked. Thank you both.

2 Likes

If it worked 4 u, pls mark it as solution.