Me and my friends make questionable things, and I need to make a flickering light that only flickers back on when you message a certain command. The flickering is fine, it's just the command isn't working. Please help, I don't understand what is wrong. Here is the full script.
local bulb = script.Parent
local light = bulb.SpotLight
local command = "*hits light*"
local hittimes = math.random(25,50)
print("Max times to hit the light:"..hittimes..".")
local onoff = 1
local counttimes = 0
light.Brightness = 12.28
bulb.Color = Color3.new(0.972549, 0.85098, 0.427451)
--establishing prior bulb
local function flickoff()
local waittime = math.random(60,120)
local flickers = math.random(1,4)
print(waittime,flickers)
--wait waittime
wait(waittime)
--flicker
for i=1,flickers,1 do
light.Brightness = 0
bulb.Color = Color3.new(0,0,0)
wait(.1)
light.Brightness = 12.28
bulb.Color = Color3.new(0.972549, 0.85098, 0.427451)
wait(.1)
end
light.Brightness = 0
bulb.Color = Color3.new(0,0,0)
end
local function flickon()
local flickers = math.random(1,4)
print(flickers)
--flicker
for i=1,flickers,1 do
light.Brightness = 12.28
bulb.Color = Color3.new(0.972549, 0.85098, 0.427451)
wait(.1)
light.Brightness = 0
bulb.Color = Color3.new(0,0,0)
wait(.1)
end
light.Brightness = 12.28
bulb.Color = Color3.new(0.972549, 0.85098, 0.427451)
end
local function bulbgo()
if counttimes<=hittimes then
if onoff == 1 then
flickoff()
onoff=onoff-1
else
light.Brightness = 0
bulb.Color = Color3.new(0,0,0)
end
end
end
bulbgo()
game:GetService("Players").PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
--print(plr.Name.." said "..msg..".")
local asd = string.find(msg,command)
if asd == 1 then
flickon()
onoff=onoff+1
bulbgo()
else
end
end)
end)``

1 comment
Thank you so much!