How to Create a Flashlight

This lession will show you how to create a flashlight.

by ItzJimPlayz_YT

Author Avatar

Your Game needs to be R15 for the animations to work.

To start of creating the flashlight you will create a tool in workspace.

img|80x45

When that is done create a Script in the tool.

local on = false

When the tool is active/using it will send a list of things to do.

script.Parent.Activated:Connect(function()

The script checks if it is really activated and skip the line.

    if on == false then
        on = true
        script.Parent.Light.Shadow.Enabled = true
        script.Parent.Light.Light.Enabled = true
        script.Parent.Light.Sound:Play()
        script.Parent.Front.SurfaceLight.Enabled = true

If it is disactivated then it disables the light and plays a different sound.

    elseif on == true then
        on = false
        script.Parent.Light.Shadow.Enabled = false
        script.Parent.Light.Light.Enabled = false
        script.Parent.Light.Sound2:Play()
        script.Parent.Front.SurfaceLight.Enabled = false
    end
end)

Now this script is done you can now create a local script.

img|80x45

This is what you need to write in the localscript

    local OldC

function oldC(oldC0)
    OldC = oldC0
end

If the tool is equipped it does the list of things.

script.Parent.Equipped:Connect(function()

    local oldC0 = script.Parent.Parent.RightUpperArm.RightShoulder.C0
    oldC(oldC0)
    while wait() do

Checks if the tool is in the players character/activated.

        if script.Parent.Parent:FindFirstChild("Humanoid") then
            local Character = script.Parent.Parent
            local Shoulder = Character.RightUpperArm:FindFirstChild("RightShoulder", true)
            local Root = Character:WaitForChild("HumanoidRootPart")
            local CameraDirection = Root.CFrame:toObjectSpace(workspace.CurrentCamera.CFrame).lookVector.unit

            Shoulder.C0 = CFrame.new(Shoulder.C0.p) * CFrame.Angles(math.asin(CameraDirection.y), -math.asin(CameraDirection.x), 0)
        end    
    end
end)

If it is unequipped then it does the list of things.

script.Parent.Unequipped:Connect(function()
    wait(0.1)
    script.Parent.Parent.Parent.Character.RightUpperArm.RightShoulder.CurrentAngle = 0
    script.Parent.Parent.Parent.Character.RightUpperArm.RightShoulder.DesiredAngle = 0
    script.Parent.Parent.Parent.Character.RightUpperArm.RightShoulder.MaxVelocity = 0
    script.Parent.Parent.Parent.Character.RightUpperArm:FindFirstChild("RightShoulder", false)
    script.Parent.Parent.Parent.Character.RightUpperArm.RightShoulder.C0 = OldC
end)

Your scripts are done but you don't have any handle or light well I got your back you can get a handle here

roblox.com/library/10745848522

After insterting the model put the parts/handles in the tool.

And Your Finished!

Tips you can do

View in-game to comment, award, and more!