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

Custom Player Model from script that still dies on explosion?

Asked by 5 years ago
Edited 5 years ago

Hi, I am making a game where certain players are "disguised" as pumpkins. I am trying to get it so that upon death from an explosive force that rips the rig apart causing death, they respawn as a pumpkin model. So far I have this code:

local fakeChar = game.ServerStorage.Model -- The character to load
local respawnTime = 1
game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            print "die"
            playerAdded(player)
        end)
    end)
end)

function playerAdded(player)
    if player.Character and player.Character.Parent then -- Destroy an already-existing character
        player.Character:Destroy()
    end

    while player.Parent do -- Repeat until they leave the game
        loadChar(player) -- Method waits until they die
        wait(respawnTime)
    end
end

function loadChar(player)
    local char = fakeChar:clone()
    char.Name = player.Name

    local humanoid
    for i, child in pairs(char:GetChildren()) do -- Find the humanoid
        if child.ClassName == "Humanoid" then
            humanoid = child
            break
        end
    end

    if not humanoid then -- If no humanoid was found, make one
        humanoid = Instance.new("Humanoid", char)
    end

    player.Character = char
    char.Parent = game.Workspace
    humanoid.Health = 100
    humanoid.Died:wait() -- Wait until they die
end

This works to some degree. However, once the player's default character model has died, if the pumpkin then explodes again, while the pumpkin model flies away, the player can walk around while the pumpkin model stays where it was (dunno if that makes any sense)

This is the Model referenced in the script: https://i.imgur.com/CbBbIGM.png The "Torso" is simply a mesh of the pumpkin, while the "HumanoidRootPart" is an invisible part.

Does anyone know how I can achieve my desired result? Basically, if I copy the player's starting model and paste it into the Model in serverstorage, it works fine, but using a custom model does not. Thanks.

0
print is not a command, it's a function DeceptiveCaster 3761 — 5y
0
this is Roblox Lua. not Python 2 DeceptiveCaster 3761 — 5y
0
neither is it JavaScript DeceptiveCaster 3761 — 5y
0
What? I fail to see you're point. I get print is a function, but if you simply want to print a string then the above works. ShrekWasMyIdea 2 — 5y

1 answer

Log in to vote
0
Answered by
ben0h555 417 Moderation Voter
5 years ago

It might be a problem of the joints not breaking or it might be a problem of the humanoid not implementing physics on the RootPart, try replacing the code with this:

local fakeChar = game.ServerStorage.Model -- The character to load
local respawnTime = 1
game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
        player.Character:BreakJoints()
        player.Character:FindFirstChildOrClass("Humanoid").PlatformStand = true
            print "die"
            playerAdded(player)
        end)
    end)
end)

function playerAdded(player)
    if player.Character and player.Character.Parent then -- Destroy an already-existing character
        player.Character:Destroy()
    end

    while player.Parent do -- Repeat until they leave the game
        loadChar(player) -- Method waits until they die
        wait(respawnTime)
    end
end

function loadChar(player)
    local char = fakeChar:clone()
    char.Name = player.Name

    local humanoid
    for i, child in pairs(char:GetChildren()) do -- Find the humanoid
        if child.ClassName == "Humanoid" then
            humanoid = child
            break
        end
    end

    if not humanoid then -- If no humanoid was found, make one
        humanoid = Instance.new("Humanoid", char)
    end

    player.Character = char
    char.Parent = game.Workspace
    humanoid.Health = 100
    humanoid.Died:wait() -- Wait until they die
end

Ad

Answer this question