Why doesn't my code work?

I think roblox studio is broken.
look at my code:

while true do
if script.UsingValue.Value == true then
	script.Parent.ImageTransparency = 0
else
	script.Parent.ImageTransparency = 1
	end
end

bug:
Screen Shot 2023-02-01 at 5.55.39 PM

workspace:
Screen Shot 2023-02-01 at 5.54.18 PM

Is the LocalScript inside the Workspace?, if so, the Client cannot run it.

1 Like

That error happens because not everything loads at once. Also your game will most likely freeze and crash because of the while true do loop.

local UsingValue = script:WaitForChild("UsingValue")

-- you don't need a while loop, just detect when it changes
UsingValue:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.ImageTransparency = UsingValue.Value and 0 or 1
    -- this basically means: if UsingValue.Value == true then set it to 0, else set it to 1
end)
1 Like

Not Exactly

You can use a Regular Script and change the RunContext to Client, this will make it a LocalScript and can run in the workspace

When calling the bool value just use :WaitForChild()

1 Like

Maybe the value didnt load in yet, try adding a :WaitForChild()
Also I suggest doing what @calvin_coco said, its much more efficient

I think this is because local scripts cannot access parts that arent made in said script. you will have to do something like this:

local UsingValue = Instance.new("BoolValue")
UsingValue.Parent = script
UsingValue.Value = true --default is false, set it to whatever you want

while true do
	task.wait() --so it doesnt crash you
	if UsingValue.Value == true then
		script.Parent.ImageTransparency = 0
	else
		script.Parent.ImageTransparency = 1
	end
end

doesn’t work, but I did make a few changed

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