Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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?

0
Have you declared a local radius? fr2013 88 — 5y
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 User#19524 175 — 5y
0
Thanks for posting that incapaz, a really good read. Should clear up his issue as well. DinozCreates 1070 — 5y
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. Neon_isHere 100 — 5y
0
It actually didn't work, but it's alright. The problem is the loop will only run once and wont continue to run. Neon_isHere 100 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

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. Neon_isHere 100 — 5y
0
If you add print("loop") after "while wait() do" does it only print "loop" one time? ChiefWildin 295 — 5y
Ad

Answer this question