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)``
string.find()
returns two numbers, not one.
The second number describes the point in the string where the pattern stops. The first describes where that pattern starts.
I'll give you two options here, you can either just check to see if find returns something...
if asd then -- other code end
...or use sub:
local asd = msg:sub(1, #command) if asd == command then -- other code end