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

How do I adjust the script so that it clones a script into player?

Okay, I made this script so when the player's health is 0, then it clones the script called deathscript to the character. Sadly the results didn't come according to plan. I tried rewriting it many times. I'm a beginner scriptwriter, and I would appreciate if you help me and tell me the problem.

local player = game.Players.LocalPlayer.Character
local humanoid = player.Humanoid

while wait() do
	local dead = script.deathscript:Clone()
	if humanoid.Health <= 0 then
		dead.Parent = player
	end
end

1 answer

✓ Accepted answer

You should use the .Died event that the humanoid object has. It will trigger when the humanoid/player dies(i.e health is 0 or <):

local player = game.Players.LocalPlayer.Character
local humanoid = player.Humanoid

while wait() do
    local dead = script.deathscript:Clone()
    humanoid.Died:connect(function()
        dead.Parent = player;   
    end)
end

2 comments

0

There's no reason to leave the "while" loop here. It's best if you remove it.

0

Oh that's true. I completely overlooked it.

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