Hey, i made a tool. When clicked, it clones a minion and is parented to workspace. It moves and follow the player. I want to make the while true do in the background, as it cannot finish the function until the while true do is stopped. I also want to do this so i could 'summon' more minions. I tried making a 'return false' but it would be an error. Is there any other ways to do this?
function MinionControl(MinionModel)
MinionModel.PrimaryPart = MinionModel:FindFirstChild("CenterPart")
wait(0.1)
MinionModel:SetPrimaryPartCFrame(tool.Parent.Torso.CFrame)
local bodyposition = Instance.new("BodyPosition")
bodyposition.Parent = MinionModel:FindFirstChild("CenterPart")
bodyposition.MaxForce = Vector3.new(500000000, 500000000, 500000000)
while true do
bodyposition.position = tool.Parent.Torso.Position + Vector3.new(math.random(-range.Value, range.Value), math.random(0, 6), math.random(-range.Value, range.Value))
MinionModel:FindFirstChild("CenterPart").CFrame = CFrame.new(MinionModel:FindFirstChild("CenterPart").CFrame.p, tool.Parent:FindFirstChild("Torso").CFrame.p)
wait(0.5)
end
end
tool.Equipped:connect(function()
tool.Activated:connect(function()
if enabled == false and tool.Parent:FindFirstChild("Humanoid") and tool.Parent:FindFirstChild("Humanoid").Health > 0 then
enabled = true
local cloneminion = minion:Clone()
cloneminion.Name = tool.Parent.Name
cloneminion.Parent = workspace
MinionControl(cloneminion)
wait(cooldown.Value)
enabled = false
end
end)
end)

2 comments
use a spawn function
^ (For line 22, more specifically.)