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

Help with humanoid?

Asked by 8 years ago

So in my game i have soldiers and i need to spawn them at different points in my game but those points arent really defined points as in random sorta thing i guess so is there a way to move my soldier possibly without his welds breaking when i spawn him?

local function weld(model, base)
    for i, v in pairs(model:GetChildren()) do
        if v:IsA("BasePart") or v:IsA("Union") and v.Name ~= base.Name then
            local w = Instance.new("Weld", game.JointsService)
            w.C1 = v.CFrame:toObjectSpace(base.CFrame)
            w.Part0 = base
            w.Part1 = v
            v.Anchored = false
        elseif v:IsA('Model') then
            weld(v, base)
        end
    end

    base.Anchored = false
end

local function handleUnit(player, building, unit)
    if debounce == 0 then
        debounce = 1

        if unit == 'Soldier' then           
            local offsets = {}

            for z, x in pairs(game.ServerStorage.Soldier:GetChildren()) do
                if x:IsA("BasePart") or x:IsA("Union") and x.Name ~= 'Torso' then
                    offsets[z] = x.Position - game.ServerStorage.Soldier.Torso.Position
                end
            end

            local dummy = game.ServerStorage.Soldier:Clone()

            dummy.Torso.Position = building.rally.Position + Vector3.new(0, 1, 0)

            for z, x in pairs(dummy:GetChildren()) do
                if x:IsA("BasePart") or x:IsA("Union") and x.Name ~= 'Torso' then
                    x.Position = dummy.Torso.Position + offsets[z]
                end
            end

            local new = dummy:Clone()
            new.Parent = game.Workspace
            new.Torso.BrickColor = colors[building.team.Value]
            weld(new, new.Torso)
            wait()
            new.Humanoid:MoveTo(new.Torso.Position + Vector3.new(10, 0, 0))

            game:GetService('Debris'):AddItem(dummy, 3)
        end

        debounce = 0
    else
        wait()
        handleUnit(player, building, unit)
    end
end
0
any script? minetrackmania 186 — 8y
0
added script ProfessorSev 220 — 8y
0
!!!THIS IS NOT A REQUEST SITE!!! We can only HELP you with your scripts, and not MAKE them for you! We need your script, and output, if any! lightpower26 399 — 8y
1
added a script ProfessorSev 220 — 8y

Answer this question