So i have a script for a flashlight you can use it whenever you want i wanna make it only usable on a equipped gun that i have can someone help me. This is the script:
local mouse = game.Players.LocalPlayer:GetMouse() function Light() player = game.Players.LocalPlayer playerChar = player.Character playerLight = playerChar.Torso:FindFirstChild("Light") if playerLight then playerLight:Destroy() else light = Instance.new("SurfaceLight",playerChar:FindFirstChild("Torso")) light.Name = "Light" light.Range = 15 light.Brightness = 5 light.Shadows = true local play = Instance.new("Sound",playerChar:FindFirstChild("Head")) play.SoundId = "http://www.roblox.com/asset/?id=198914875" play:Play() end end mouse.KeyDown:connect(function(key) key = key:lower() if key == "l" then Light() end end)
local tool = game.Workspace.Gun local plr = game.Players.LocalPlayer local mouse = game.Players.LocalPlayer:GetMouse() function Light() player = game.Players.LocalPlayer playerChar = player.Character playerLight = playerChar.Torso:FindFirstChild("Light") if playerLight then playerLight:Destroy() else light = Instance.new("SurfaceLight",playerChar:FindFirstChild("Torso")) light.Name = "Light" light.Range = 15 light.Brightness = 5 light.Shadows = true light.Enabled = true --Its something like this local play = Instance.new("Sound",playerChar:FindFirstChild("Head")) play.SoundId = "http://www.roblox.com/asset/?id=198914875" play:Play() end end mouse.KeyDown:connect(function(key) key = key:lower() if key == "l" and tool.Parent == plr.Character then Light() end end)