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

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

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)

3 comments

0

Is this a local or server script?

0

Where is the script located?

0

server script and its in startercharacterscripts

1 answer

✓ Accepted answer

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.

3 comments

0

ok

0

Thanks so much!!! it worked!

0

Glad I could help!

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