Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Custom Player Model from script that still dies on explosion?

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.

4 comments

0

print is not a command, it's a function

0

this is Roblox Lua. not Python 2

0

neither is it JavaScript

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.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.