Script doesnt work (SIMPLE)

So what im trying to do is a button that changes the color of a part, Here is the script that explains where the part and the button is:

local Color = Color3.fromRGB(255,0,0)
local lights = game.Lighting.StageLights.Part – Btw “Lightning” is a folder.

script.Parent.MouseButton1Click:Connect(function()
lights.Color = Color
end)

Please help me look for what i missed? :slight_smile:

5 Likes

I tested the script for myself and it seems to be working fine, the issue may be how you’re defining the lights variable.

Can you send a screenshot of the Part inside of the explorer tab?

ezgif-7-ee02cd1074

2 Likes

Thanks for your time, Here is a screenshot:
see the model with multiple parts? Thats the lights (the white lines on the screen)
And the button is the red one on the color palette

1 Like

The issue is that you didn’t put Workspace after game., so instead it should be;

local Color = Color3.fromRGB(255,0,0)
local lights = game.Workspace.Lighting.StageLights.Part

script.Parent.MouseButton1Click:Connect(function()
	lights.Color = Color
end)
3 Likes

Ok so i added workspace on my own script and it works, but i want to change the color of all parts of the model yk? It only changes one part to red

3 Likes

I think they meant to say:

local lights = game.Workspace.Lightning.StageLights.Part
4 Likes

The issue is that you have many parts called ‘Part’ inside the model.

2 Likes

well yeah so how do i script it so it changes to color of all parts?

2 Likes
local lights = workspace.Lightning.StageLights
local color = Color3.fromRGB(255,0,0)

script.Parent.MouseButton1Click:Connect(function()
	for _,lightPart in pairs(lights:GetChildren()) do
	    if lightPart:IsA("Part") then
		    lightPart.Color = color
	    end
    end
end)
2 Likes

Didnt work at all, Are u sure its spelled correct?

2 Likes

The issue is that there are multiple parts inside of the StageLights model and you’re only changing a single part. Also you’re refering to game.Lighting when your target folder is in the workspace

fixed code:

local Color = Color3.fromRGB(255,0,0)
local lights = workspace.Lightning.StageLights

script.Parent.MouseButton1Click:Connect(function()
	for i, v in pairs(lights:GetChildren()) do
		v.Color = Color
	end
end)
4 Likes

Sorry, try again, I thought you meant Lighting and not Lightning. I updated my code.

1 Like

Now this works thank you sooo much :smiley:

1 Like

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