New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

How would you prevent joints from breaking when player dies?

Asked by 4 years ago

Could anyone tell me how I could prevent the player's limbs from falling off when the player dies?

0
You mean like a ragdoll? TheDeadlyPanther 2437 — 4y
0
Use welds or motors? We don't actually know what you want here.. Chronomad 180 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You may want to use a fake health system. Allow me to explain.

The first thing you want to do is make a variable inside the player called PHealthor whatever you want to call it. I'm going to use PHealth for this example.

We can add it like so. (script inside workspace or serverscriptservice)

game.Players.PlayerAdded:connect(function(plr)

H=Instance.new("IntValue",plr)
H.Name="PHealth"
H.Value=100
end)

So now we have a health variable inside the player with a value of 100.

Next, we'll need to add the character's death activator. (inside a LocalScript in StarterPack)

wait(.01)

while wait() do

if game.Players.LocalPlayer.PHealth.Value<1 then

 game.Players.LocalPlayer.PHealth.Value=100

--do the code that activates when a player dies here.

end

--and here we'll set MaxHealth.

if game.Players.LocalPlayer.PHealth.Value>100 then
game.Players.LocalPlayer.PHealth.Value=100

end

end

Now we don't want the player resetting via the menu, right? We can fix this by renamingHumanoid in the player. Now we can add this as an updated version of the above script.

wait(.01)

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Name="MyHumanoid"

while wait() do

if game.Players.LocalPlayer.PHealth.Value<1 then

 game.Players.LocalPlayer.PHealth.Value=100

--do the code that activates when a player dies here.

end

--and here we'll set MaxHealth.

if game.Players.LocalPlayer.PHealth.Value>100 then
game.Players.LocalPlayer.PHealth.Value=100

end

end

Lastly, here's a sample script of a part that will kill the player. Though the player is unafected if he/she has a forcefield.


script.Parent.Touched:connect(function(hit) if hit.Parent:findFirstChild("MyHumanoid") and not hit.Parent:findFirstChild("ForceField") then game.Players:GetPlayerFromCharacter(hit.Parent).PHealth.Value=0 end end)

I hope this little explanation helped you out! If you liked it, hit that accept button!

PS: Please attempt you own code before coming here. If you did, post your code so we can fix it.

Ad

Answer this question