So what this excerpt from my script does is that whenever an attack (gui button) is selected, it selects it and checks for "AOE". If there is a value for "AOE", then it makes the aoecircle appear under the player with a circumference of the AOE. My problem is with removing the circle; how do I make it both remove the circle from Workspace, set the variable nil, but at the same time stop the "RenderStepped" coroutine from running? Currently, it sets newaoe to nil and then RenderStepped returns hundreds of error messages, essentially crashing the game. Any help would be appreciated!
local aoecircle = Instance.new("Part")
aoecircle.Anchored = true
aoecircle.Transparency = 0.5
aoecircle.CanCollide = false
aoecircle.Material = "Neon"
aoecircle.BrickColor = BrickColor.Red()
local aoemesh = Instance.new("CylinderMesh",aoecircle)
local newaoe = nil
function changeStats(atk,bar,info)
a1:FindFirstChild("AttackName").TextColor3 = Color3.new(0,0,0)
a2:FindFirstChild("AttackName").TextColor3 = Color3.new(0,0,0)
a3:FindFirstChild("AttackName").TextColor3 = Color3.new(0,0,0)
a4:FindFirstChild("AttackName").TextColor3 = Color3.new(0,0,0)
if selectedAttack ~= atk then
selectedAttack = atk
selectedBar = bar
selectedInfo = info
selectedAttack:FindFirstChild("AttackName").TextColor3 = Color3.new(1,1,1)
cas:BindAction("useMove", attack, false, Enum.UserInputType.MouseButton1)
if selectedInfo["AOE"] then
newaoe = aoecircle:clone()
newaoe.Size = Vector3.new(selectedInfo["AOE"],1,selectedInfo["AOE"])
newaoe.Parent = game.Workspace
coroutine.resume(coroutine.create(function()
game:GetService("RunService").RenderStepped:connect(function()
newaoe.CFrame = game.Players.LocalPlayer.Character.Torso.CFrame - Vector3.new(0,2,0)
end)
end))
end
else
selectedAttack = nil
selectedBar = nil
selectedInfo = nil
cas:UnbindAction("useMove")
newaoe = nil
end
end

1 comment
Nvm, switched to BindToRenderStep and it has a built-in way to unbind it. Fixed.