Code issues - What's wrong with my code?

Hello, I need help with my code, could someone help me to solve it, please?
This basically means that when the player dies, the body is cloned and thrown on the ground, could someone help me fix it? please

StarterCharacterScripts code:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		print("Alive")

		Humanoid.Died:Connect(function()
			local debris = game:GetService('Debris')
			local character = script.Parent
			local player = game.Players:GetPlayerFromCharacter(script.Parent)
			local humanoid = character:WaitForChild('Humanoid')
			local bodyDisposeTime = 30
			-- code
			if player ~= nil and humanoid ~= nil then
				character.Archivable = true

				script.Parent = game.ServerScriptService

				local cloneChar = character:Clone()
				cloneChar.Name = player.Name.."'s Deadbody"

				if workspace:FindFirstChild(cloneChar.Name) then
					workspace:FindFirstChild(cloneChar.Name):Destroy()
				end

				wait(0.1)
				cloneChar.Parent = workspace

				local rootPart = cloneChar.HumanoidRootPart or cloneChar.Torso
				local clonedHumanoid = cloneChar:FindFirstChildOfClass("Humanoid")
				cloneChar:MoveTo(rootPart.Position)

				rootPart.Orientation = Vector3.new(90,0,0)
				clonedHumanoid.PlatformStand = true
				clonedHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				clonedHumanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff

				for i, v in pairs(cloneChar:GetChildren()) do
					if v:IsA("BasePart") then
						v.Anchored = false
						v.CanCollide = false
					end
					if v:IsA("Script") or v:IsA("LocalScript") then
						v:Destroy()
					end
				end

				if cloneChar:FindFirstChild("ForceField") then
					cloneChar.ForceField:Destroy()
				end

				character.Parent = game:GetService("ServerStorage")

				debris:AddItem(cloneChar,bodyDisposeTime)
				debris:AddItem(script,bodyDisposeTime)	

				wait(1)

				if rootPart.Orientation ~= Vector3.new(90,0,0) then
					rootPart.Orientation = Vector3.new(90,0,0)
					rootPart.Anchored = true
				end
				-- end code

				-- revive
				wait(45)
				Character:LoadCharacter()
			end
		end)
	end)
end)

What’s the issue you are occurring?

Your code is really confusing, you should put this in ServerScriptService at first, not in StarterCharacterScript.

Make sure it’s a Script and not a LocalScript

You already have the Character argument given with Player.CharacterAded so you don’t need to define character again, same for the player.

It does look like you tried jamming some code you don’t know together.

2 Likes

I need to know how to correct it to get the player’s body replicated.