im trying to code a custom death script instead of dying the player will go down and stand up after a while but i cant get the character back into the same position as the downed clone, clone.position is coming back as nil i think loadcharacter automatically removes it so i cant use its position, is there a way around this?
local deathspot
local revspot
local rs = game.ReplicatedStorage
local deathevent = rs.downeddeath
local downedevent = rs.Downed
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
character.Humanoid:UnequipTools()
deathspot = character.PrimaryPart.Position
local plrdwn = player.leaderstats.Downed
local humanoid = character:WaitForChild("Humanoid")
local oldCFrame = character:GetPrimaryPartCFrame()
local downedinv = {}
for i,v in ipairs(player.Backpack:GetChildren()) do
local tool = v
if tool then
table.insert(downedinv,v.Name)
print(v.Name)
end
end
if plrdwn.Value == false then
wait()
plrdwn.Value = true
character.Archivable = true
local downedplr = character:Clone()
downedplr.Archivable = false
character.Archivable = false
downedplr.Parent = workspace
downedevent:FireClient(player,downedplr)
local newcharhumanoid = downedplr:WaitForChild("Humanoid")
downedplr.PrimaryPart.Position = deathspot
newcharhumanoid.MaxHealth = 200
newcharhumanoid.Health = 200
local Animator = downedplr.Humanoid:WaitForChild("Animator")
local Animation = Instance.new("Animation")
local downedpose = Instance.new("Animation")
downedpose.AnimationId = "rbxassetid://10907012341"
Animation.AnimationId = "rbxassetid://7257093097"
local AnimationTrack = Animator:LoadAnimation(Animation)
local downedposetrack = Animator:LoadAnimation(downedpose)
AnimationTrack:Play()
AnimationTrack.Stopped:Connect(function()
downedposetrack:Play()
end)
wait()
player.Character:Destroy()
player.Character = downedplr
for i, v in pairs(downedinv) do
print("itemdataloaded")
local toolstoclone = game.ServerStorage.Allitems:FindFirstChild(v)
if toolstoclone then
local clone = toolstoclone:Clone()
wait(1)
clone.Parent = player:WaitForChild("Backpack")
end
end
newcharhumanoid.WalkSpeed = 1
newcharhumanoid.JumpHeight = 0
wait(5)---------------------------time until stand up
if downedplr then
revspot = downedplr.PrimaryPart.Position
downedplr:Destroy()
player:LoadCharacter()
character.PrimaryPart.Position = revspot
player.Character = character
plrdwn = false
workspace.Camera.CameraType = "Custom";
end
newcharhumanoid.Died:Connect(function()
downedplr:Destroy()
player:LoadCharacter()
plrdwn.Value = false
deathevent:FireClient(player,downedplr)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value/2
end)
end
end)
end)
player:LoadCharacter()
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.