local d=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local C=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local G=game:GetService("\080\108\097\121\101\114\115")local W=C:GetTagged("\076\105\103\104\116\117\112\066\117\116\116\111\110")local q={}local Y={}for d,C in pairs(W)do q[C]={active=false}end local function D(d)d.CharacterAdded:Connect(function(C)repeat task.wait(.2)until C and(C.PrimaryPart and C.Humanoid)Y[d]=C end)d.CharacterRemoving:Connect(function(C)Y[d]=nil end)end G.PlayerAdded:Connect(D)for d,C in pairs(G:GetChildren())do D(C)end while true do local d=C:GetTagged("\076\105\103\104\116\117\112\066\117\116\116\111\110")for d,C in pairs(d)do if q[C]==nil then q[C]={active=false}end end for d,C in pairs(q)do C.active=false end for C,G in pairs(Y)do if G and(G.PrimaryPart and G.Humanoid)then local C=RaycastParams.new()C.FilterDescendantsInstances=d C.FilterType=Enum.RaycastFilterType.Whitelist local W=workspace:Raycast(G.PrimaryPart.Position,Vector3.new(0,-6,0),C)if W and W.Instance then if q[W.Instance]then q[W.Instance].active=true end end end end task.wait()for d,C in pairs(q)do if C.active then d.Material=Enum.Material.Neon else d.Material=Enum.Material.Plastic end end end
-- this will need to be worked into a client schema later
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

local taggedButtons = CollectionService:GetTagged("LightupButton")

local buttons = {}
local characters = {}

for _, button in pairs(taggedButtons) do
	buttons[button] = {
		active = false,
	}
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(character)
		repeat
			task.wait(0.2)
		until character and character.PrimaryPart and character.Humanoid

		characters[player] = character
	end)
	player.CharacterRemoving:Connect(function(character)
		characters[player] = nil
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

for _, player in pairs(Players:GetChildren()) do
	onPlayerAdded(player)
end

while true do
	local taggedButtons = CollectionService:GetTagged("LightupButton")

	for _, button in pairs(taggedButtons) do
		if buttons[button] == nil then
			buttons[button] = {
				active = false,
			}
		end
	end

	for _, button in pairs(buttons) do
		button.active = false
	end

	for player, character in pairs(characters) do
		if character and character.PrimaryPart and character.Humanoid then
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = taggedButtons
			raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
			local raycastResult =
				workspace:Raycast(character.PrimaryPart.Position, Vector3.new(0, -6, 0), raycastParams)

			if raycastResult and raycastResult.Instance then
				if buttons[raycastResult.Instance] then
					buttons[raycastResult.Instance].active = true
				end
			end
		end
	end

	task.wait()

	for instance, button in pairs(buttons) do
		if button.active then
			instance.Material = Enum.Material.Neon
		else
			instance.Material = Enum.Material.Plastic
		end
	end
end
