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

How do I Make My Tool a Flashlight With a Key Input?

Asked by
TofuBytes 500 Moderation Voter
10 years ago

I'm trying to get an equip tool to enable a SpotLight when you press "F". I'm also trying to get the tool to turn off when you press "F" again. Any help on this? I've been trying to fix it.

local tool = script.Parent
local light = script.Parent.Handle.SpotLight

tool.Selected:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
        if key == "f" then
        light.Enabled = true
        else
        light.Enabled = false
        end            
    end)
end)

1 answer

Log in to vote
0
Answered by 10 years ago
local tool = script.Parent
local light = script.Parent.Handle.Spotlight
a = Instance.new("BoolValue")
a.Parent=tool
a.Value.Value=false

tool.Selected:connect(function(mouse)
    mouse.KeyDown:connect(function(key)
        if key == "f" then
        if script.Parent.Value.Value=false then
            light.Enabled=true
            script.Parent.Value.Value=true
        else
            light.Enabled=false
            script.Parent.Value.Value=false
        end
    end
    end)
end)

Should work although not tested.

0
It doesn't work. TofuBytes 500 — 10y
Ad

Answer this question