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

How would i clone an object and put it in workspace??

Asked by 4 years ago
Edited 4 years ago

I made this dead script thingy it works fine besides it wont put the clone in workspace...

Character = script.Parent
Dead = game.Lighting.Dead
Humanoid = Character.Humanoid

function OnDeath()
    wait(0.5)
    game.lighting.Dead:Clone()
    Dead.Parent = game.Workspace 
    game.Workspace.Dead.HumanoidRootPart.Position = Character.HumanoidRootPart.Position
    Dead.Parent = game.Workspace
end
Humanoid.Died:connect(OnDeath)
0
Is this a local or server script? User#25069 0 — 4y
0
Where is the script located? iResioku 15 — 4y
0
server script and its in startercharacterscripts Deinonychusaurus 21 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I'm trying to understand what you're doing, but front what I can read you're trying to get a model from lighting, clone it and parent it to workspace. Then making that model be in the same position the character is when the character dies.

Assuming that I can actually go about fixing this.

--//Putting "local" in front of variables only used in the scope that it's in is good practice

local Character = script.Parent
local Dead = game.Lighting.Dead:Clone() --//Getting our Dead model. I'm calling clone here because just in case anything happens to the model inside of lightning, we'll always have a copy.
local Humanoid = Character.Humanoid

function OnDeath()
    local rootPosition = Character:GetPrimaryPartCFrame() --//Getting the CFrame of the root of the character
    local deadClone = Dead:Clone() --//Cloning our Dead model from lighting

    wait(0.5)

    deadClone:SetPrimaryPartCFrame(rootPosition) --//I'm assuming that it has a primarypart in it because it has a HumanoidRootPart inside of it.
    deadClone.Parent = game.Workspace 
end

Humanoid.Died:connect(OnDeath)

I describe most of what I'm doing in the scripts comments, but I'm basically just doing what I said above.

0
ok Deinonychusaurus 21 — 4y
0
Thanks so much!!! it worked! Deinonychusaurus 21 — 4y
0
Glad I could help! CeramicTile 847 — 4y
Ad

Answer this question