I have this code that uses RunService .Heartbeat:Connect that is inside a function, but the problem is, there is a check in the start that kinda works for just not doing everything else in the code. i want to know if this check is still being made for every frame? this check is going to run for every single time i call the function like if it was a task.spawn? and if so, how can i disconnect the function for it to stop checking? here is the code
run.Heartbeat:Connect(function()
if not building then return end -- the check im talking about
local mouse = uis:GetMouseLocation()
local camray = camera:ViewportPointToRay(mouse.X, mouse.Y)
local rayparams = RaycastParams.new()
rayparams.FilterType = Enum.RaycastFilterType.Include
rayparams.FilterDescendantsInstances = {workspace.Mapa.Tiles}
local ray = workspace:Raycast(camray.Origin, camray.Direction * 10000, rayparams)
if ray and ray.Instance then
highlight.Parent = ray.Instance
ghostpart:PivotTo(CFrame.new(ray.Instance.CFrame.Position + Vector3.new(0, ghostpart:GetExtentsSize().Y/2, 0)))
currenttile = ray.Instance
end
if table.find(tilesplanted, currenttile) or ray == nil then
highlight.FillColor = Color3.new(1,0,0)
canput = false
else
highlight.FillColor = Color3.new(1,1,1)
canput = true
end
end)