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

How do I make a chest flashlight?

Asked by 10 years ago

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

Log in to vote
0
Answered by 4 years ago

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)

Ad

Answer this question