How can i implement this to a mobile button?

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.

PS: Use google search.

EDIT:

2 Likes

Here is a kickstart for ya

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

Goodluck!

  • oh and you can remove the uis now
2 Likes

Thanks! Might try this later…

1 Like

Thankyou! It works

#Nothing to add

1 Like