I Have created a context action service script which makes a button appear for mobile players I only want that button to be visible if a part is touched and when they come of the part I want it to be invisible again how do I script that?
I haven’t tested this.
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local ACTION_NAME = "Action" -- replace with your own action name
local part = -- the part
local plr = Players.LocalPlayer
local touchEndConn
local function handleInput(inputState, inputObj)
-- your code here
end
local function touchEnded()
local tParts = part:GetTouchingParts()
local char = plr.Character
local isTouching = false
for i, v in ipairs(tParts) do
if v.Parent == char then
isTouching = true
break
end
end
if not isTouching then
ContextActionService:UnbindAction(ACTION_NAME)
touchEndConn:Disconnect()
touchEndConn = nil
end
end
local function touched(hit)
if hit.Parent ~= plr.Character or touchEndConn then
return
end
ContextActionService:BindAction(ACTION_NAME, handleInput, true, --[[input types here]])
touchEndConn = part.TouchEnded:Connect(touchEnded)
end