Oh ye! I was testing in actuall game so i couldn’t see errors after leaving but i tested in studio and it seems that i have error:
Is there any way i can save value of tool that equipped/inside character?
i will try add waitforchid
Oh ye! I was testing in actuall game so i couldn’t see errors after leaving but i tested in studio and it seems that i have error:
Is there any way i can save value of tool that equipped/inside character?
i will try add waitforchid
I think Character might be removed before your script runs
Try to add waitforchild and see what happens then
Wait for child isn’t going to help it clearly says attempt to index nil which means Humanoid parent isn’t there
Yeah wait for the parent which is the character
local character = plr.Character or plr.CharacterAdded:Wait()
yeah… it didn’t gave any error but it don’t work
that’s not going to work either instead use
player.CharacterRemoving
i can use this function inside this one?
The reason why you are getting this error is because you spelt Humanoid
wrong. Here is your code with the correct spelling:
game.Players.PlayerRemoving:Connect(function(player)
player.Character.Humanoid:UnequipTools()
local valuesToSave = {}
for _, v in pairs(player.Backpack:GetChildren()) do
valuesToSave[v.Name] = v:WaitForChild("Amount").Value
end
MyDataStore:SetAsync(player.UserId, valuesToSave)
end)
Instead of using SetAsync() you should look into using UpdateAsync() because
“SetAsync() can be hazardous since it overwrites any value currently in the entry. If you’re updating an existing entry, UpdateAsync() is recommended because it considers the old value before making changes.” - Quoted from the developers hub
There is 1 problem with this actually that It would fire everytime player respawn
He spelled humanoid wrong thats why it wasnt working.
lol didn’t noticed that. but it still don’t save
i noticed that if i remove humanoid:UnequipTools() then it will save
As i was wondering Now here is what you can do get a Character Removed event in Your script and do the
there
You can then later just save it in main function
Have you activated the HTTPS Service in Studio? You can try in-game (not studio) if this can help.
This doesn’t use HttpService, so HttpEnabled is not relevant.
Using :UnequipTools() is not required and the reason why it errors is because your character is already removed by the time PlayerRemoving fires.
@megatank58 using CharacterRemoved can be hazardous as it fires every time you die. Never do this for anything involving anything but in game death.
This is datastore, and datastore need the https service to be activted.
Nvm, go to: Home»GameSettings»Options and enable „Enable Studio Access to API Services“
You might want to use pcall() so it finishes the code properly.
I know I haven’t recommended it here and i have also started it’s back effects