Keep Character After Death?

  1. I want to keep the character after Respawn/Death

  2. I heard about that i should try with DataStore but idk how to script it

  3. How does it work with DataStore, Do u have other Solutions

following script it that one for changing the Character

local Characters = game.ReplicatedStorage:WaitForChild("Characters")

script.Parent.MouseButton1Click:Connect(function(player, chosenCharacter)
	-- Setze chosenCharacter fest auf "Rubixcube"
	chosenCharacter = "Rubixcube"

	if Characters:FindFirstChild(chosenCharacter) then		
		local newChar = Characters:FindFirstChild(chosenCharacter):Clone()
		local plrChar = script.Parent.Parent.Parent.Parent.Parent.Character

		newChar.PrimaryPart = newChar.Torso
		newChar:SetPrimaryPartCFrame(plrChar.PrimaryPart.CFrame)
		newChar.Name = script.Parent.Parent.Parent.Parent.Parent.Name
		if plrChar:FindFirstChild("Animate") and not newChar:FindFirstChild("Animate") then
			plrChar.Animate:Clone().Parent = newChar
		end
		if plrChar:FindFirstChild("Health") and not newChar:FindFirstChild("Health") then
			plrChar.Health:Clone().Parent = newChar
		end
		script.Parent.Parent.Parent.Parent.Parent.Character = newChar
		local rootPart = newChar:FindFirstChild("HumanoidRootPart")
		local plrRoot = script.Parent.Parent.Parent.Parent.Parent.Character:FindFirstChild("Torso")
		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end
		newChar.Parent = game.Workspace
		for i, part in pairs(newChar:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Anchored = false
			end
		end
	end
end)

Only use DataStore for long-term saving solutions. For short-term solutions, you need to use a table on the memory. That said, to contain this data, use {} and a variable on the global scope.

-- here is global scope
local characterData = {}

do 
    -- one instance of local scope, do not write here
end
1 Like

Problem solved by my own thx for help !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.