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

How to kill and replicate into a new character?

Asked by 5 years ago
Edited 5 years ago

I am having trouble creating a script that goes in a part, kills a player, and then replicates a child of the plrModel and puts it in the new torso of the living character. No portion of the code executes properly.

local plr = game.Players.LocalPlayer
local plrModel = game.ReplicatedStorage:WaitForChild(plr.Name)
local particle = plrModel:FindFirstChild()

function onTouched(hit)
print("death test")
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
human.Health = 0
    end
end

function touchedMe(hit)
    print("test")
    if particle ~= nil then
        print("test1")
        local newClone = particle:Clone()
        local newCharacter = game.Workspace:WaitForChild("plr.Character"):WaitForChild("UpperTorso")
        newClone.Parent = newCharacter
        print("test2")
    end
end

script.Parent.Touched:connect(onTouched)
script.Parent.Touched:connect(touchedMe)


Nothing in this script is executing. Its purpose, is to clone any particle from the PlayerModel located in ReplicatedStorage after the player dies. Do you know how I could fix it? The player is not dying.

0
Is this a server script? User#19524 175 — 5y
0
No, it is inside of a part. RandomMildChicken 11 — 5y
0
Then of course it wont work. Local scripts must be a descendant of a player character in order to execute under workspace. User#19524 175 — 5y
0
And do you mind indenting your code so we can actually read it? Plus studio auto indents so how do you not indent your code. It helps us read it and you too User#19524 175 — 5y
View all comments (3 more)
0
I indented it, but what should I do with it in order to fix this? RandomMildChicken 11 — 5y
0
Make it a script and on your own get the player, as LocalPlayer is seen as nil by the server User#19524 175 — 5y
0
I have gotten player on my own, but still nothing executes. RandomMildChicken 11 — 5y

Answer this question