i keep getting the error message “infinite yeild possible” even though im 1000% sure this code is correct. im a newer developer so dont critisize me to much.
Any help as soon as possible would be amazing!
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
One why do you have two waits, you have wait(1), and then a wait at the end of the while loop. Two, it’s probably waiting for your player to be found in the workspace… if I had to guess. I’m pretty sure that’s a warning, so it doesn’t error your code out, it just is infinitely waiting for something it isn’t finding.
I’m not sure what the “codeprime8”( love the guy by the way ) Instance is supposed to be, but it doesn’t appear to be inside of the workspace from the screenshot you showed.
yea. to be honest im reading from a book right now to learn so im not 100% what it is either. what i do is copy what he wrote, see his explanation, then try it on my own. he never said to add and parts or add it as a child to any parts in the workspace like he normally does so im just confused why it got an error.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local myPart = Instance.new("Part",workspace)
local myPos = Vector3.new(0,10,0)
local myLook = Vector3.new(0,1,0)
local myCFrame = CFrame.new(myPos,myLook)
myPart.Anchored = true
while(1) do --while loops are infinite.--
myPart.CFrame = myCFrame
user = char
myLook = user.HumanoidRootPart.Position
myCFrame = CFrame.new(myPos,myLook)
wait()
end
end
end
what are you talking about? i literally just changed your code and put it into the characteradded function [when your player is added to the game/worksapce… basically when you see yourself. the only thing that would need to be done is ensure the player actualy exists incase they leave, or die. other than that, that’s exactly what you were asking for.
nevermind with it.
i thought the person of the book was saying for the part to follow the player but it just looks at them. Thanks for the help! you guys are amazing. thank you for your time! it works now.
Don’t want to bump your code to much, but while loops are not meant to be infinite. It creates memory leaks which can disrupt gameplay and induce more lag. RunService.RenderStepped is a good alternative. Also yielding nothing is bad practice. If you need a better understanding on why I say this, I have created a post discussing this bad practice which can be found here:
This is being run on the server, therefore RenderStepped won’t work without this being moved to the client-side. Not to mention, it sounds like they’re working their way into learning. Adding too many concepts right now will only make their learning process very difficult right now.
That is why I told the OP that. When they are learning, it is easier to learn not to use bad practice. That is because they haven’t used it a lot since they are learning. RenderStepped is for the client and Stepped and Heartbeat is for the server.
And you recommended RenderStepped for server-side. They already said they don’t understand function connections, and it sounds like they’re reading a book on Roblox development. I would let them mature a bit before you add too much into this.