Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My code for turning off the lights doesn't work,why?

I have a button so when someone walks over it, the other 2 scripts activate.

local function onTouch(hit)
	workspace.blackout.Disabled = false
	workspace.neon.Disabled = false
	
end

script.Parent.Touched:Connect(onTouch)

It works. Then I tagged lightpoints and parts using a plugin that works and I scripted these 2 scripts.

local CollectionService = game:GetService("CollectionService")

local TaggedParts = CollectionService:GetTagged("light")

for _, TaggedParts in pairs(TaggedParts) do
	light.Enabled = false
	
end

But the lights don't turn off. Then there is a script for turning neon material to plastic:

local CollectionService = game:GetService("CollectionService")

local TaggedParts = CollectionService:GetTagged("plastic")

for _, TaggedParts in pairs(TaggedParts) do
	Enum.Material.Plastic
	
end

But that also doesn't work. If anyone knows where the error is and how to fix it,please correct me in the comments, thanks

1 answer

✓ Accepted answer

What are you trying to do here?

local CollectionService = game:GetService("CollectionService")
	 
	local TaggedParts = CollectionService:GetTagged("plastic")
	 
	for _, TaggedParts in pairs(TaggedParts) do
	    Enum.Material.Plastic
	 
	end

You are just typing Enum.Material.Plastic

I think you wanted to do this:

local CollectionService = game:GetService("CollectionService")
	 
	local TaggedParts = CollectionService:GetTagged("plastic")
	 
	for _, TaggedParts in pairs(TaggedParts) do
	    TaggedParts.Material = Enum.Material.Plastic
	end

Now to disable the light you should do

local CollectionService = game:GetService("CollectionService")
	 
	local TaggedParts = CollectionService:GetTagged("light")
	 
	for _, TaggedParts in pairs(TaggedParts) do
	    TaggedParts.Enabled = false
	end

This discussion is preserved as it was. New answers, comments, and votes are closed.