Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Ball teleports to player when in radius, script wont loop?

while wait() do
    if (center-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude <= radius then
    game.Workspace.Basketball.Handle.CFrame = game.Workspace.Neon_isHere.HumanoidRootPart.CFrame
end
end

I CANNOT figure this out for the life of me, (there are variables i just didnt put them in the thread.)

This won't loop? It's supposed to give it to me everytime i get in radius but it wont, it will only execute upon the first time being executed/played and wont every other time i get close. could somebody help me out a little?

5 comments

0

Have you declared a local radius?

1

Please, make use of the conditional portion of the while loop and read this document made by CntKillMe: https://docs.google.com/document/d/1ieZ8OzXPiXe3R7rs_xWmYZOnhQevlagN0ZWwoj_zKP4/edit

0

Thanks for posting that incapaz, a really good read. Should clear up his issue as well.

0

Thank you very much incap! I thought about this but I figured it wouldn't continue to loop. I'll try this now, even if it doesn't work the post helped me learn a little.

0

It actually didn't work, but it's alright. The problem is the loop will only run once and wont continue to run.

1 answer

Your problem is most likely the fact that you're not updating the 'center' variable as the loop runs. You mentioned that it is a ball, so it is most likely changing constantly. Move your variable definition for 'center' to the first line after "while wait() do" so that it constantly updates the variable as the loop runs.

It would look something like this:

while wait() do
	center = workspace.Ball.Position
	if (center-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude <= radius then
		game.Workspace.Basketball.Handle.CFrame = game.Workspace.Neon_isHere.HumanoidRootPart.CFrame
	end
end

I'm also assuming that 'center' is a Vector3 value defining some position and that 'radius' is a float value already pre-defined. If I'm wrong on either account, please adjust your script accordingly so that I'm not.

2 comments

0

This works but i'm still having the same issue, the loop wont repeat. Upon execute it will only occur once and when the ball goes from the players backpack back to the workspace, it won't repeat the loop.

0

If you add print("loop") after "while wait() do" does it only print "loop" one time?

This discussion is preserved as it was. New answers, comments, and votes are closed.