Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Simple on and off/boolean value not working?

I have a simple thing so when a value that is in ReplicatedStorage is set to false, the brick will be CanCollide off and Transparency 1. But when it is set to true, it does the opposite. Here is my code:

local val = game.ReplicatedStorage.IsFalling.Value
local target = game.ReplicatedStorage.IsFalling

target.Changed:connect(function()
	warn("Change")
	if val == true then
		script.Parent.Protection.Transparency = 0.4
		script.Parent.Protection.CanCollide = true
	elseif val == false then
		script.Parent.Protection.Transparency = 1
		script.Parent.Protection.CanCollide = false
end end)

It's function is firing, I could tell from the "warn" i put in there. What's wrong with my code?

1 answer

✓ Accepted answer

When defining val, you have to define the actual BoolValue, not its property called Value. Also, the new value comes as a parameter to the Changed event, so there's no need. If you want to know the value, outside of the changed event, though, you would put target.Value instead.

local target = game.ReplicatedStorage.IsFalling

target.Changed:Connect(function(val)
	warn("Change")
	script.Parent.Protection.Transparency = (val and 0.4) or 1 -- this way is more efficient.
	script.Parent.Protection.CanCollide = val -- as is this way.
end)

1 comment

0

Your code half-fixed my problem, but I did the other half, so i might as well accept the answer :P

This discussion is preserved as it was. New answers, comments, and votes are closed.