Hello, I have a building system within my game which includes a RenderStepped event binded to n variable named “deleteConnection”. deleteConnection is used to show a selection box around any objects that the mouse hovers over. My issue is when my cancel function, which runs :Disconnect(), continues to run for some reason.
(I’ve removed any extra code so its easier to read)
delete function:
function BuildHandler.delete()
deleteConnection = RunService.RenderStepped:Connect(function()
local boundingBox = mouse.target.Parent.Parent:FindFirstChild("BoundingBox")
if lastTarget ~= nil and lastTarget ~= boundingBox then
--removes some selection box effect
end
if boundingBox then
--does some selection box effect
lastTarget = boundingBox
end
end)
end
cancel function:
function BuildHandler.cancel()
if buildConnection and item then
buildConnection:Disconnect() --this works fine to cancel building
item:Destroy()
item = nil
end
if deleteConnection then
deleteConnection:Disconnect()
print(deleteConnection) --still prints connection
--removes selection box effect if its still visible
end
end
If anyone can inform me why this is happening, that would be great. Thanks.