How can I make this script work within a ImageButton

title, this script was made in a tool but i decided it better to make a gui for it.
here’s the scripts:
script for the tool:

                                 ---------------------------------------------VARIBLES-------------------------------------------------
local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent(blueblock)")
local runService = game:GetService("RunService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 1.5
local blueBlock = game.ReplicatedStorage:WaitForChild("BlueBlock")
local shadow_block = blueBlock:Clone(); shadow_block.Transparency = .5; shadow_block.Parent = workspace.Blocks.ShadowBlocks; shadow_block.CanCollide = false
if shadow_block.CanCollide == true then
	print("BRUH")
end

mouse.TargetFilter = shadow_block

                                ---------------------------------------------FUNCTIONS-------------------------------------------------

function snapToGrid(x)
	return math.floor(x/grid + 0.5)*grid
end

function calculateY(toP, toS, oS)
	return (toP + toS * 0.5) + oS * 0.5
end

runService.RenderStepped:Connect(function()
	if mouse.Target ~= nil then
		shadow_block.Position = Vector3.new(snapToGrid(mouse.Hit.Position.X), calculateY(mouse.Target.Position.Y, mouse.Target.Size.Y, blueBlock.Size.Y), snapToGrid(mouse.Hit.Position.Z))
	end

	if tool:FindFirstAncestorWhichIsA("Model") ~= player.Character then
		shadow_block.Transparency = 1
	else
		shadow_block.Transparency = .5
	end
end)

tool.Activated:Connect(function()
	if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
		print(shadow_block.Position)
		remoteEvent:FireServer("blueBlock", shadow_block.Position)
		print("script is working")
	end
end)

script inside serverscriptservice:


local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent(blueblock)")

remoteEvent.OnServerEvent:Connect(function(player, block, position)
	print(position)
	local clone = game.ReplicatedStorage:WaitForChild("BlueBlock"):Clone()
	clone.Parent = workspace.Blocks.BlueBlocks
	clone.Position = position
end)

PLEASE HELP