How can I use the property of something to make a part visible?

I’m trying to make it so that the localscript I’m using checks if the property of another part equals a certain value, then makes the part parenting it visible. I’m kind of new to scripting so I don’t know how a lot of things work but this is the code I have:

local hat = script.Parent

local variable = game.Workspace.Variable.PointLight

if variable.Range == 1 then

game.Workspace.hat.Transparency = 0

end

I’ve checked in game and the other scripts that change the value of the variable have worked but for some reason this script doesn’t. Did I put it in the wrong place? The part that’s parenting the localscript is in the workspace

1 Like

You can use PropertyChangedSignal to run a function when the property of a object changes and you can use an If statement to see if the new property value is equal to the desired one

In your case, it would look something like this:

local hat = script.Parent

local variable = game.Workspace.Variable.PointLight

variable.GetPropertyChangedSignal:Connect(function()

     if variable.Range == 1 then

          hat.Transparency = 0

     end

end)


BTW I would recommend using a Script instead of a LocalScript because LocalScripts only replicate on the client and unless you want the hat to become visible ONLY for 1 player, I advise you switch to a Script.

Also, LocalScripts do not run when they are a descendant of workspace

1 Like

It is only checking if that factor is true once, try using a changed function and then check the factor.

1 Like