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

i tried to make a flashlight, but it work when key is down, how to make key press?

script:

local light = Instance.new('SurfaceLight')
local humanoidrootpart = script.Parent:WaitForChild("HumanoidRootPart")


repeat wait() until game.Players.LocalPlayer


local humanoidrootpart = game.Players.LocalPlayer.character:WaitForChild("HumanoidRootPart")
local mouse = game.Players.LocalPlayer:GetMouse()
light.Parent = humanoidrootpart
light.Brightness = 0


mouse.KeyDown:connect(function(key)
	if key == "f" then

		
		script.flashlight_on:Play()
		light.Brightness = 5
		

	end


end)


mouse.KeyUp:connect(function(key)
	if key == "f" then

		
		script.flashlight_off:Play()
		light.Brightness = 0


	end


end)

1 comment

0

and yes, it is in startercharacter scripts, and inside of a local script

2 answers

✓ Accepted answer

Put the below in a localscript

local Mouse = game.Players.LocalPlayer:GetMouse()
local on = false
local pointLight = script.Parent.FlashLightHead.PointLight 
--set pointLight to the location of the PointLight that controls the flashlight's light
Mouse.Button1Down:Connect(function()
if on then
on = false
pointLight.Range = 0
else
on = true
pointLight.Range = 8
end
end

1 comment

0

thx

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