Data wont save and wont show any errors

could i add others stuff like defense KI etc

1 Like

i edited ur code fixed 2 errors and now it works thanks!

1 Like

added more stats too in the script

1 Like

What was the errors ?
Have a nice day @Tanks_altNum1 and @Vertires !

in the server script

	for v, ValueInstance in pairs(Player.leaderstats) do
		if ValueInstance:IsA("ValueBase") then
			Data[ValueInstance.Name] = ValueInstance.Value
		end
	end

this part had error

for v, ValueInstance in pairs(Player.leaderstats) do

the Player.leaderstats had error since the error said table expected so i changed it to this

local mainstats = Player.MainStats
	for v, ValueInstance in pairs(mainstats) do
		if ValueInstance:IsA("ValueBase") then
			Data[ValueInstance.Name] = ValueInstance.Value
		end
	end
1 Like

Oh my bad you only have to do this :

for v, ValueInstance in pairs(Player.leaderstats:GetChildren()) do

can i use my version which i use now also idk how to make bindtoclose so ye

1 Like

No you can’t since in my script I’m getting leaderstats children and I don’t understand what you want to make with bind to close ?

i heard that you need to keep bindtoclose

1 Like

also idk since my version still works

1 Like

I took a look at your code and I don’t understand cause in your old code you were trying to save players data when the server shut down but you’re already saving their data when they leave so you don’t need to keep !
EDIT : plus you’re trying to get player but they doesn’t exist since they leaved the game !

1 Like

I will update the message where I send you the code !

i know since i keep getting this error BindToClose failed because the model is already being closed.

1 Like

oops in mine code this is the part i forgot to look in my code

local mainstats = Player.Gmultis:GetChildren()
	for v, ValueInstance in pairs(mainstats) do
		if ValueInstance:IsA("ValueBase") then
			Data[ValueInstance.Name] = ValueInstance.Value
		end
	end
1 Like

You don’t need mainstats since you can do Player.leaderstats:GetChildren() !

yeah i know but ill keep it since it still works so ye

1 Like

i use 4 different leaderstats scripts since in 1 script a lot of them wont be created

2 Likes

hi back again! here’s a link to a similar issue i just helped a guy with

DataStore not saving, Not getting an error or success message - Help and Feedback / Scripting Support - Developer Forum | Roblox

to use game:BindToClose(function()

as shown im my post

yeah since that i improved in scripting a lot now mostly i dont get errors and if i do i can fix them easily

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