Hey guys, I was wondering how do you make it so a certain light on a gun (script.Parent.Light.Light1) is enabled when you hit f, and disabled when you hit it again?
Also is it easy to just copy it if I wanted to make 2 lights in a gun?
Hey guys, I was wondering how do you make it so a certain light on a gun (script.Parent.Light.Light1) is enabled when you hit f, and disabled when you hit it again?
Also is it easy to just copy it if I wanted to make 2 lights in a gun?
You can copy this script, just change the key (Obviously...)
Equipped = false
on = false
light = script.Parent.PointLight
script.Parent.Equipped:connect(function(Equipped)
Equipped = true
end)
mouse.KeyDown:connect(function(key)
local key = key:lower()
if Equipped and key == "f" and on == false then
light.Enabled = true
on = true
elseif Equipped and key =="f" and on == true then
light.Enabled = false
on = false
end
end)
--[[script.Parent.Unequipped:connect(function()
light.Enabled = false
end)--]]
--The above is if you want it to auto-set the light off if they put away the tool
-Thank me by accepting this answer/bumping up my reputation!
mouse=Game.Players.LocalPlayer:GetMouse();
light=WHERE_TO_FIND_THE_LIGHT;
mouse.KeyDown:connect(function(key)
if key:lower()=='f' then
light.Enabled=not light.Enabled;
end;
end);
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
Does this script go inside the brick with the light, or do I copy it into the script that controls the gun's functions (so it's all one script)?
Copy this into the gun script.
Adding this into the gun script and modifying it so the path to the light is correct does not seem to work.
On the connection line, is the path correct? I just put script.Parent because I assumed that the script was a direct child of the tool.
The script IS a direct child, but you have that the pointlight is a part of the tool, which it isn't. It's in a block that's in the tool. I changed it to script.Parent.Light.Light1, with the name of the block being "Light" and the name of the light being "Light1."