as you can see it went back and forth, i tried while true do and game.heartbeat, both did the same thing, any idea why?
while true do
wait()
if (circle.Position - plr.Character.HumanoidRootPart.Position).Magnitude < 50 then
if grabbed == true then
circle.Position = mouse.Hit.Position
else
circle.Position = Vector3.new(0,0,0)
end
else
circle.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,-2,3)
end
end
it could be that grabbed is set to after an input is finished, causing the circle to revert back to Origin, and then the else statement triggers, causing it to be placed behind the character. Try implementing a print statement to find where you went wrong. If possible, you can also get rid of the statement setting the circle to appear behind you.
EDIT: Reread your code. As the circle gets placed 50 studs away from you, the circle gets teleported to vector3.zero. After that, the else statement is still triggered by the first paramater of the “If” statement being false (it’s no longer inside 50 studs.) This cycle exists because the circle’s new position is now inside the 50 stud radius, causing it to move back to your mouse. Break that cycle and you’re good
local far = false
while true do
wait()
if (circle.Position - plr.Character.HumanoidRootPart.Position).Magnitude < 50 and not far then
if grabbed == true then
circle.Position = mouse.Hit.Position
circle.Transparency = 0
else
—-I assume you wanted to make the cursor not be visible, so
circle.Transparency = 1
wait(2)
far = false
else if not far then
circle.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,-2,3)
far = true
end
end
end
You can create a denounce to prevent the function from alternating between these loops, but it’s basically a cycle of being moved far away and then close, you should pay attention to that in the future. Also, I wrote this on an iPad and have no way of formatting or checking the code, so sorry if there is syntax or issues like that. Lmk if you need more help,