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.
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