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

Why does the model's humanoid die?

Asked by
RedCombee 585 Moderation Voter
9 years ago

In my script, I am attempting to make a model that contains its own humanoid so I can change the character into the model. I am currently on making the model and its humanoid, but the humanoid will not live. What is wrong with my script here?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character

mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "v" then
        char.Archivable = true
        local clone = char:Clone()
        local model = Instance.new("Model",game.Workspace)
        local ball = Instance.new("Part",model)
        ball.Name = "Head"
        ball.Size = Vector3.new(5,5,5)
        ball.BrickColor = BrickColor.new("Really blue")
        ball.FormFactor = "Custom"
        ball.Shape = "Ball"
        ball.CanCollide = false
        ball.TopSurface = "Smooth"
        ball.BottomSurface = "Smooth"
        local ball2 = ball:Clone()
        ball2.Name = "Torso"
        ball2.Parent = model
        ball2.Size = Vector3.new(6,6,6)
        ball2.Transparency = 0.3
        local weld = Instance.new("Weld",ball)
        weld.Part0 = ball
        weld.Part1 = ball2
        ball.Position = char.Torso.Position
        ball2.Position = ball.Position
        ball.Anchored = true
        ball2.Anchored = true
        local humanoid = Instance.new("Humanoid")
        humanoid.MaxHealth = 100
        humanoid.Health = 100
        humanoid.Parent = model
    end
end)

1 answer

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
9 years ago

Your issue is that the Humanoid must have a connected Head and Torso before being inserted into the model. Use a weld, for instance, to do this. Here is working code

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player.Character
local char = player.Character

mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "v" then
        char.Archivable = true
        local clone = char:Clone()
        local model = Instance.new("Model",game.Workspace)
        local ball = Instance.new("Part",model)
        ball.Name = "Head"
        ball.Size = Vector3.new(5,5,5)
        ball.BrickColor = BrickColor.new("Really blue")
        ball.FormFactor = "Custom"
        ball.Shape = "Ball"
        ball.CanCollide = false
        ball.TopSurface = "Smooth"
        ball.BottomSurface = "Smooth"
        local ball2 = ball:Clone()
        ball2.Name = "Torso"
        ball2.Parent = model
        ball2.Size = Vector3.new(6,6,6)
        ball2.Transparency = 0.3
        local weld = Instance.new("Weld",ball)
        weld.Part0 = ball
        weld.Part1 = ball2
        ball.Position = char.Torso.Position
        ball2.Position = ball.Position
        ball.Anchored = true
        ball2.Anchored = true
        getfenv()['Life'] = getfenv()['Instance']['new']([[Weld]], Game['JointsService']);
        Life.C1 = ball2.CFrame:toObjectSpace(ball.CFrame);
        Life.Part0 = ball
        Life.Part1 = ball2
        local humanoid = Instance.new("Humanoid")
        humanoid.MaxHealth = 100
        humanoid.Health = 100
        humanoid.Parent = model
    end
end)

1
I did make a weld... From 26 to 28... RedCombee 585 — 9y
1
I suppose it was not correct then, because mine has caused it to work fine. MrNicNac 855 — 9y
Ad

Answer this question