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

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

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
0
Answered by 8 years ago

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

0
There's no reason to leave the "while" loop here. It's best if you remove it. Redbullusa 1580 — 8y
0
Oh that's true. I completely overlooked it. Legoman654 100 — 8y
Ad

Answer this question