✓ Accepted answer
Is the script in the light part a local script? Local scripts don't run in workspace unless they are under the player's character. Here's a list of where local scripts can run:
A LocalScript will only run Lua code if it is a descendant of one of the following objects:
- A Player’s Backpack, such as a child of a Tool
- A Player’s character model
- A Player’s PlayerGui
- A Player’s PlayerScripts.
- The ReplicatedFirst service
https://developer.roblox.com/en-us/api-reference/class/LocalScript
You have to place the local script in one of those areas for it to run.
If the script in the light part is not a local script, but is a normal Script, it still won't run because you're cloning the light part on the client, so the server Script will not be cloned along with the part. To fix this, you have to execute the code in a Local Script. What you can do is run the code inside the main Local Script as well, like so:
local server = game:GetService("Workspace")
local lightClone = server.Light:Clone()
lightClone.Parent = workspace.CurrentCamera
game.Workspace.Light:Destroy()
local light = lightClone.SpotLight
local sound = lightClone.Sound
print("K")
light.Enabled = false
wait(8)
light.Enabled = false
sound:Play()
light.Enabled = true
wait(.5)
light.Enabled = false
wait(.1)
light.Enabled = true
wait(1)
light.Enabled = false
wait(.2)
light.Enabled = true
game.Workspace.Lights.Value = 1
sound:Stop()
Keep in mind that this means that game.Workspace.Lights.Value is only set to 1 for the client, and not everyone else. The same goes for playing and stopping the sound, the sound will only play and stop for the client who has this local script.
2 comments
Thank you!
It's exactly what I wanted it to do, only play for the client who has the script so it worked amazingly well.