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

RocketPropulsion slowing down the more humanoids there are?

Asked by 10 years ago

So basically, I made a turret that detects when a humanoid is in its range, and it will fire missiles at it, that fly towards the humanoid using RocketPropulsion. It works just fine, however when there are many humanoids in the place (NOT within he turrets range!), the missiles just get slow. And I mean, really slow. The moment I get rid of all the humanoids, it returns to normal speed. And its only the missiles that are slow; the rest of the place moves around and runs just fine.

So yeah, why is this happening? The game is a MOBA by the way, so if you know what that means, this effect occurs the moment minions spawn. Here's the code if you want to see the turret script, there will be some things you wont understand though :

local arr = { }
local delay = 2-- speed of shooting
local tempdelay = 0
local previouschar
local range = 52
while wait(0.1) do
    arr = { }


    for _,v in pairs(script.Parent:GetChildren()) do
        if v:IsA("ObjectValue") then table.insert(arr,v) end
    end

    if #arr > 0 then
        local ind = 1
        if (Workspace:FindFirstChild(arr[1].Name) == nil) then 
            arr[1]:Destroy()
        else
            local minrange = (script.Parent.Torso.Position - Workspace[arr[1].Name].Torso.Position).magnitude
            for i = 1,#arr do
                local r = (script.Parent.Torso.Position - Workspace[arr[i].Name].Torso.Position).magnitude
                if (r < minrange and r <= range) then
                    minrange = r
                    ind = i
                end
            end
            if minrange <= range then
                local char = Workspace:findFirstChild(arr[ind].Name)
                if char ~= nil then
                    if game.Players:FindFirstChild(char.Name) ~= nil then
                        if game.Players[char.Name]:findFirstChild("Ding") == nil then
                            local dng = script.Parent.Ding:Clone()
                            dng.Parent = game.Players[char.Name]
                            dng:Play()
                        end
                        script.Parent.DetectorV.BrickColor = BrickColor.Red()
                    else
                        if (previouschar ~= nil) then
                            if (game.Players:findFirstChild(previouschar.Name) ~= nil) then
                                if game.Players[previouschar.Name]:findFirstChild("Ding") ~= nil then
                                    game.Players[previouschar.Name].Ding:Destroy()
                                end
                            end
                        end
                        script.Parent.DetectorV.BrickColor = BrickColor.Green()
                    end
                    if tempdelay >= delay then
                        tempdelay = 0
                        local sht = script.Parent.Shoot:Clone()
                        sht.Parent = char.Torso
                        sht:Play()
                        local hitsound = script.Parent.Hit:Clone()
                        local blast = script.Parent.Diamond:Clone()
                        blast.Script:Destroy()
                        blast.Transparency = 0.3
                        blast.CanCollide = false
                        blast.Anchored = false
                        blast.Name = "Blast"
                        blast.Parent = script.Parent
                        blast.CFrame = script.Parent.Diamond.CFrame
                        local rp = Instance.new("RocketPropulsion",blast)
                        rp.ThrustP = 3 * char.Humanoid.WalkSpeed
                        rp.MaxSpeed = 3 * char.Humanoid.WalkSpeed
                        local targ = Instance.new("StringValue",blast)
                        targ.Name = "Target"
                        targ.Value = arr[ind].Name
                        local fire = Instance.new("Fire",blast)
                        if blast.BrickColor.Name == "Bright green" then
                            fire.Color = Color3.new(0.5,1,0)
                            fire.SecondaryColor = Color3.new(0,1,0)
                        else
                            fire.Color = Color3.new(0.5,0,1)
                            fire.SecondaryColor = Color3.new(0,0,1)
                        end
                        hitsound.Parent = blast
                        local sc = script.BlastScript:clone()
                        sc.Parent = blast
                        sc.Disabled = false
                    end
                    previouschar = char
                end
            end     
        end
    else
        script.Parent.DetectorV.BrickColor = BrickColor.Yellow()
    end
    tempdelay = tempdelay + 0.1
end

Here is the Missile Script :

local diam = script.Parent
local rp = diam:findFirstChild("RocketPropulsion")
local targ = diam:findFirstChild("Target")
local hit = diam:findFirstChild("Hit")
if (rp == nil or targ == nil or hit == nil) then
    print("Lacking rocketpropulsion or target or sound")
    script.Parent:Destroy()
end

local char = Workspace:FindFirstChild(targ.Value)
if char ~= nil then
    rp.Target = char.Torso
    rp:Fire()
    print("Fired")
end

rp.ReachedTarget:connect(function()
    if char ~= nil then
        char.Humanoid:TakeDamage(10)
        hit:Play()
    end
    script.Parent:Destroy()
end)

Thanks in advance!

Answer this question