So, i created a script using ContextActionService; ContextActionService is a service similar to UserInputService, but has buttons that work on IPhone's, and iPad's.

What I'm trying to achieve is when i'm close to the block it shows the button, that i mentioned earlier and when you press it, it triggers the function.

My problem is that it's firing the function even though i have not pressed the button yet. Advanced help needed.

(This is a Local Script)

If you want to please do, since i have a problem with procrastinating.

Here's the 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 true do
wait(1)
if (Torso.Position - Part.Position).magnitude <= AggroMag then
ContextActionService:BindAction("turnBrickYellow", OnPress, true, "t")
ContextActionService:SetPosition("turnBrickYellow", UDim2.new(0.72,-25,0.20,-25))
   else
   ContextActionService:UnbindAction("turnBrickYellow")
	end
	end