So, In this case I'm using ContextActionService, it's similar to UserInputService, but the benefits of ContextActionService is including mobile buttons.
What I'm trying to achieve is making the button appear when I'm close to the block. Everything works fine, but the brick color is adjusting every second?
I think it's because i have a while loop, but it does not work if i remove the while loop.
Here's the local script:
local ContextActionService = game:GetService("ContextActionService")
local AggroMag = 50
wait(2)
local Character = game.Players.LocalPlayer.Character
local Torso = Character:FindFirstChild("HumanoidRootPart")
local Part = game.Workspace.Part
local function OnPress()
Part.BrickColor = BrickColor.Random()
end
while wait(1) do
if (Torso.Position - Part.Position).magnitude <= AggroMag then
ContextActionService:BindAction("turnBrickYellow", OnPress, true, "t")
else
ContextActionService:UnbindAction("turnBrickYellow")
end
end

2 comments
Oh, nice let me check it!
It works, but the IO's version the button is flickering.