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

How do you get multiple Point Lights from Multiple Parts?

DO NOT MIND THE MESSY CODE, I AM A BEGINNER AND THIS IS MY FIRST TIME CODING A FULL GAME.

At the beginning, there is a group called Lights as you can see from the local Purchase. Inside that group, there is multiple parts called "LightPart" and multiple parts called "Part" Inside each of the "LightPart" there is a point light.

Now, this may be complex, but how do I enable and disable the point light in these groups?

local Price = 130
local timedelay = 0.5
local amount = 1
local currencyname = "Cash"
local Purchase = game.Workspace.Purchases.LumberMill.Lights:GetChildren()
Touch = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if script.Parent.Transparency == 0 then
			Touch = true
		end
		if Touch == true then
			if player.leaderstats.Cash.Value >= Price then
				player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - Price
				for _,v in pairs (Purchase) do
					v.Transparency = 0
					v.CanCollide = true
				end
				script.Parent:Destroy()
					while true do
					wait(timedelay)
						for i,v in pairs(game.Players:GetPlayers()) do
							if v:FindFirstChild("leaderstats") then
								v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
						end
					end
				end
			end
		end
	end
end)

1 comment

0

What does the code do?

1 answer

✓ Accepted answer

Try:

for Index, Part in pairs(Purchase) do
	if Part:FindFirstChild("PointLight") do
		Part.PointLight.Enabled = false -- or true, depending on what you want.
	end
end

Note: The Index is a place holder. It is usually replaced with _ but I like naming things

3 comments

0

Thanks!! can you explain what Index is suppost to do at line 1?

0

Index or i

0

Index is just a placeholder

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