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 a chest flashlight?

Like the one used in Half Life 2. Where you can press "F" and when you do, a flashlight turns on. I need a flashlight, that isn't a tool, you can have it on even when you have a weapon out, and I need it to follow your camera. If anyone can help me with this, please help.

1 answer

Here's the solution to make a flashlight in the player's humanoid!

local mouse = game.Players.LocalPlayer:GetMouse()
function Light()
	player = game.Players.LocalPlayer
	playerChar = player.Character
	playerLight = playerChar.UpperTorso:FindFirstChild("Light")-- For R6 games: "Torso"
	if playerLight then
		playerLight:Destroy()
	else
		light = Instance.new("SurfaceLight",playerChar:FindFirstChild("UpperTorso"))-- For R6 games: "Torso"
		light.Name = "Light"
		light.Angle = 90-- You can edit this
		light.Range = 30-- And this
		light.Brightness = 35-- And this
		light.Shadows = true-- And this


		local play = Instance.new("Sound",playerChar:FindFirstChild("UpperTorso"))-- For R6 games: "Torso"
		play.SoundId = "http://www.roblox.com/asset/?id=242135745"-- You can also change the clicking sound
		play:Play()
	end
end
mouse.KeyDown:Connect(function(key)
	key = key:lower()
	if key == "f" then
		Light()
	end
end)

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