Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

0

It doesn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.