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

There seems to be a problem with my loop?

Asked by
RoyMer 301 Moderation Voter
8 years ago

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
0
Does the output give you an error? funyun 958 — 8y
0
Nope RoyMer 301 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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

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. RoyMer 301 — 8y
0
Oh, sorry. Rushed the reading and didn't see the variable... darkelementallord 686 — 8y
0
alright np RoyMer 301 — 8y
Ad

Answer this question