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

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

Asked by 4 years ago

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)

0
and yes, it is in startercharacter scripts, and inside of a local script TinkyWinkyDev 6 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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
0
thx TinkyWinkyDev 6 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Try MouseClick

0
np, mouseclick is not a valid member of mouse TinkyWinkyDev 6 — 4y

Answer this question