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
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
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