Hi, i am making a tower script where when it boosts then it can give boost, but i want it to make it when the Sell Value is true in a task.spawn() function, but somehow it doesn’t work,
while task.wait(0.001) do
local high = 0
local low = 999999999999
local enemy = script.Sort
local enemies = workspace.Towers
--print('activateboost')
for i, v in pairs(enemies:GetChildren()) do
local distance = (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
local boostrange = script.Parent.BoostRange
if distance < boostrange.Value and v ~= script.Parent and script.Parent.UsingAbility.Value ~= false then
v.Torso.Shock.Enabled = true
v.FireRateBoost.Value = script.Parent.BoostPower.Value
enemy.Value = v
end
end
if script.Parent.UsingAbility.Value ~= false then
script.Parent.Torso.boost:Play()
wait(script.Parent.WaitUntilEnd.Value)
end
-- Here is it
task.spawn(function()
if script.Parent.Sold.Value == true then
for i, v in pairs(enemies:GetChildren()) do
local distance = (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
local boostrange = script.Parent.BoostRange
if distance < boostrange.Value and v ~= script.Parent then
v.FireRateBoost.Value = 1
v.Torso.Shock.Enabled = false
enemy.Value = v
end
end
else
end
end)
for i, v in pairs(enemies:GetChildren()) do
local distance = (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
local boostrange = script.Parent.BoostRange
if distance < boostrange.Value and v ~= script.Parent and script.Parent.UsingAbility.Value ~= false then
v.FireRateBoost.Value = 1
v.Torso.Shock.Enabled = false
enemy.Value = v
end
end
--print('removeboost')
script.Parent.UsingAbility.Value = false
end