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

There seems to be a problem with my loop?

For some reason which I don't know of, this loop is not working properly?

local follow = script.Parent.Parent.Parent.Range.Target.Value
local home = script.Parent.Parent.Parent.Range.Position

while wait(.1) do
	
if follow ~= "home" then
local Position = game.Workspace:FindFirstChild(follow).Torso.Position
script.Parent:MoveTo(Position)

else 	
script.Parent:MoveTo(home)	
end
end

2 comments

0

Does the output give you an error?

0

Nope

1 answer

Is the value meant to change after the loop has began running? If so, then that would be your problem. The script will cache the "follow" value, meaning that if it changes at any point, the script will still use the old value. Change the follow variable to the instance StringValue and change the stuff in the "if" to "follow.Value"

local follow = script.Parent.Parent.Parent.Range.Target
local home = script.Parent.Parent.Parent.Range.Position

while wait(.1) do

if follow.Value ~= "home" then
local Position = game.Workspace:FindFirstChild(follow.Value).Torso.Position
script.Parent:MoveTo(Position)

else    
script.Parent:MoveTo(home)  
end
end

3 comments

0

No I'm definitely sure that won't work, because the value stored in the variable follow is a String, I'm 99% sure the problem is with the loop because if I had to disable and enable another script connected to this, it works.

0

Oh, sorry. Rushed the reading and didn't see the variable...

0

alright np

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