function fire(target) ------fire print("fire") p = script.Parent.Parent.missile:Clone() p.Parent = script.Parent.Parent p.Position = script.Parent.Position + Vector3.new(0, 2, 0) p.Anchored = false p.Name = "missile"..math.random(-9999, 9999) p.Script.Disabled = false end function main() ------- Main for i, v in pairs(Workspace:GetChildren()) do --print(v) if v.Name == "Target" then --print("target1") if (script.Parent.Position - v.Position).magnitude < range then print("in range") target = v targetfound = true print("Targetfound == "..targetfound) ------------print repeat -----repeat for i = 1, 32 do move(target) wait(reload/32) end fire(target) until target == nil or (script.Parent.Position - target.Position).magnitude > range print("target lost") targetfound = false end end end wait(.5) end while true do ---------- While loop print(targetfound) if targetfound == false then main() print("main") else wait(1) end end
Ok, I know I just dumped a lot of code one you, but I'll explain my quandary now. This is my auto-turret script, and I'm trying to figure out some weird printing occurrences. In the while loop I check everytime if targetfound is equal to false. For this example assume that it is. Then we go up to the function main(). A couple lines into main I wrote print("Targetfound == "..targetfound) but this never prints. The script seems to skip over that line and go straight to the repeat section. While it is running the repeat section though, the script is also printing targetfound in the while loop, which prints as false. Please tell me if I need to rephrase my question/explain some of my code.
it won't print because you can't concatenate a boolean. The right way to code it would be like this: print("Targetfound == "..tostring(targetfound))