Hello! How can i implement this flashlight script to a mobile button using contextactionservice?Thanks!
Script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local uis = game:GetService("UserInputService")
local Enable = false
local flashlight
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
if not Enable then
Enable = true
light = Instance.new("SpotLight", char.HumanoidRootPart)
light.Brightness = 7
else
light:Destroy()
Enable = false
end
end
end)
P.S - i only know contextactionservice a bit, so yea
If you do know contextactionservice a bit, it wouldn’t be hard to make just a one mobile button with that bit knowledge; Am i right? you could try watching a youtube tutorial to help you there.
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local cas = game:GetService("ContextActionService")
local Enable = false
local flashlight
local function FlashLightEnable(actionname, inputstate)
if inputstate == Enum.UserInputState.Begin then
print(inputstate)
end
end
cas:BindAction("FlashLightEnabler", FlashLightEnable, true, Enum.KeyCode.F ) -- (ActionName, call the function, create a mobile/tablet button (boolean), keycode)
cas:SetPosition("FlashLightEnabler", UDim2.new(1, -70, 0, 10)) -- the button will show up above the mobile jump button