Script stops working in model when the model is parented to workspace

So I want the lights to turn on and off every second and the script is in a model in replicated storage and when I parent the model into the workspace the script stops working.

here is the script:

local partlight = script.Parent
local spotlight = partlight.Attachment.SpotLight
while true do
wait(1)
partlight.Material = Enum.Material.Neon
spotlight.Enabled = true
wait(1)
partlight.Material = Enum.Material.SmoothPlastic
spotlight.Enabled = false
wait(1)
end

local partlight = workspace:WaitForChild(“YourPartLightName”)
local spotlight = partlight:FindFirstChild(“Attachment”) and partlight.Attachment:FindFirstChild(“SpotLight”)

if partlight and spotlight then
while true do
wait(1)
partlight.Material = Enum.Material.Neon
spotlight.Enabled = true
wait(1)
partlight.Material = Enum.Material.SmoothPlastic
spotlight.Enabled = false
wait(1)
end
else
warn(“Partlight or Spotlight is missing.”)
end

Try this I think you were naming the part light as the parent of the script

1 Like

Is your script a LocalScript or a server Script? LocalScripts aren’t able to run inside of Workspace, so if your script is a LocalScript, then there are two methods you can use to fix your problem:

  1. If the code doesn’t need to run on the client-side, and you don’t mind having the server run the code, then replace the LocalScript with a server Script

  2. If the code needs to run on the client, or you don’t want the server to run it, then you’ll still need to replace the LocalScript with a server Script, but make sure that you change the server Script’s RunContext property to Client

1 Like

Ok wait I turned the script run context to client and it worked thanks

1 Like

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