For some reason, this local variable that I made doesn’t behave properly? I don’t know how to explain it in a short way. I am trying to create a command that creates a red circle around the player.
Code:
local RedZone
local Following
if string.lower(Radius[2]) == "destroy" and RedZone then
print("ok")
RedZone:Destroy()
Following = false
elseif string.lower(Radius[2]) ~= "destroy" then
RedZone = Instance.new("Part")
Following = true
print(Radius[2])
RedZone.Anchored = true
RedZone.BrickColor = BrickColor.new("Really red")
RedZone.CanCollide = false
RedZone.Shape = Enum.PartType.Cylinder
RedZone.Material = Enum.Material.Neon
RedZone.Transparency = 0.75
RedZone.Size = Vector3.new(0.1,Radius[2],Radius[2])
RedZone.CFrame = (Character.HumanoidRootPart.CFrame * CFrame.new(0,-Character.Humanoid.HipHeight - 1,0)) * CFrame.Angles(0,0,math.rad(90))
RedZone.Parent = Character.HumanoidRootPart
while Following do
RedZone.CFrame = (Character.HumanoidRootPart.CFrame * CFrame.new(0,-Character.Humanoid.HipHeight - 1,0)) * CFrame.Angles(0,0,math.rad(90))
RunService.Heartbeat:Wait()
end
end
When I delete the RedZone variable (the local variable that is nil originally) from the script, this happens:
Aren’t all the code under the elseif supposed to be highlighted in red too?
Same thing with the Following variable.
Plus, when I actually test out the command, even with the variables deleted, the script still works. The red circle is created and follows me. However, when I try to use the “destroy” command, it does not work unless RedZone is defined. Even if it is, it prints “ok” but does not delete the part or set Following to false. Really confused here. Sorry if it’s some sort of obvious mistake but please do point it out if it is!


