ok, if that was the problem then why only at line 5 output says?
probably make a variable like
local char = plr.Character or CharacterAdded:Wait()
because the line 6 is the event connections so the problem is inside of this connection
no it is line four???
what do you mean by line 6
line 6 is the end of the function
yes, so the problem is inside the connection thats the reason why the oput says it
The character is removed before the player, you need to hook a function to the .CharacterRemoving
event instead.
When .PlayerRemoving
fires the character has already been removed.
but the error is only at line 5…???
also does character remove fire everytime humanoid die or only when leave
You haven’t waited for the character to properly replicate before attempting to reference it.
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
yes, i did but did not work for me, and the output says that i forgot to enable the API Setting. i thought there was an error but let me turn it on and test the script
It still won’t work because you can’t save a CFrame value in datastores.
hmmnnnnnmm what can i do?
yeha what i can do
I wrote this script a few weeks ago which saves and loads a player’s character’s position.
it did not work at all anyways.
To save a CFrame in a datastore, add each value of the CFrame to a table, then save the table. Like so:
local cframe = plr.chh:FindFirstChild("HumanoidRootPart").CFrame
CFrameDataStore:SetAsync(plr.UserId, {cframe.X, cframe.Y, cframe.Z})
Let’s say the CFrame is 0, 0, 0. The table will be like this:
{
[1] = 0,
[2] = 0,
[3] = 0
}
but i not only wnat the opsiton but also rotation??
Then you can do the same thing, but with the rotation. Just switch some things out. Also, while loading the data, set each individual value, otherwise it will error. Like this:
local data = CFrameDataStore:GetAsync(plr.UserId)
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[1]
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[2]
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[3]
What didn’t work? The script I linked works & has been thoroughly tested.
let me try and test again.
i am going to tset again
oh it worked now, good
it worked
it worked
Nothing else to say
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local cFrameDataStore = dataStoreService :GetDataStore("CFrameDataStore")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local success, response = pcall(cFrameDataStore.GetAsync, cFrameDataStore, player.UserId)
if success == false then print(response) return end
local cFrame = CFrame.new(response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12])
local rootPart = character:WaitForChild("HumanoidRootPart")
rootPart.CFrame = cFrame
end)
player.CharacterRemoving:Connect(function(character)
local rootPart = character:WaitForChild("HumanoidRootPart")
local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = rootPart.CFrame:GetComponents()
local data = {x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22}
local success, response = pcall(cFrameDataStore.SetAsync, cFrameDataStore, player.UserId, data)
if success == false then print(response) return end
end)
end)