Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Flashlight in a gun?

Asked by 4 years ago

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)

1 answer

Log in to vote
0
Answered by 4 years ago
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)



0
When i unequipped the gun the light still stays how can i make it disappear ezkatka1 50 — 4y
0
Make an event for the tool. tool.Unequipped:Connect(function() not sure what the unequipped function is called. BradNewTypical 232 — 4y
Ad

Answer this question