Datastore not saving properly!

I was thinking maybe it is because I am storing it on the player?

EDIT: nvm you can store leaderstats on the player so this probably wouldn’t be different. Also another script uses this same code but just with another Datastore name

1 Like

i think that you can store( booleans / strings / numbers ) not 100% sure of that
and if you are making this for a “real” game you should add server locking or use a module that does it to prevent players from losing data

2 Likes

It won’t store the number is the problem and in another post people said if you try to store a boolean it replicates to everyone

1 Like

I am unable to replicate the issue on my side. The way it wouldn’t have saved is that somehow the value is being set to 0 another script, I’m assuming? Are you sure that there are other script that manages the OwnShovels value.

I’m pretty sure you can store boolean just as normal. You can look on the document for that.

2 Likes

what do you mean by replicate to everyone?
you can store
– numbers
– strings
– booleans
what u canot store
– instances and their properties
– things like vec3 / vec2 etc
– functions

2 Likes

Yes another script sets it to 1, but nothing sets it to 0.

Here is the other script

script.Parent.MouseButton1Down:Connect(function()
	if game.Players.LocalPlayer.leaderstats.Brix.Value >= 10 and game.Players.LocalPlayer.OwnsShovel.Value ~= 1 then
		game.Players.LocalPlayer.leaderstats.Brix.Value -= 10
		script.Parent.Parent.Parent.Visible = false
		game.Players.LocalPlayer.OwnsShovel.Value = 1
	end
	
end)
1 Like

I mean that if one person has a boolean stored then it is the same for everyone. I will show you the post I found this it

EDIT: Found it!

1 Like

Nevermind, Misread this post. It said that you can’t use it in replicated storage

I will try to use a boolean inside the player

1 Like

Doesn’t work, when I join it is set to true regardless

Add this under the save data function:

print(player.OwnsShovel.Value)

This will show us what value is being passed on.

1 Like

Oooh I think I got it to work. Lemme see

Nevermind. It won’t work, it just passes on true or false seemingly randomly every time I join

EDIT: It saved false
EDIT2: When I join it prints “The player has no data!”

The ONLY reason why it might be false/not saving, is that you are setting it on the client script, therefore it does not replicate to the server.

When you are setting the OwnShovels to true, ensure that you use a RemoteEvent to set the OwnShovels to true on a serverscript so that it saves properly (and also please use checks that the player meets the requirements on the server as you cannot trust the client)

1 Like

I have an idea, what if I just save it under my other datastore? Then I can cross out conflicting names

ok! Lemme try that rq, it probably will work

I set the value on client side but I store the current value when you leave on server side

The client side changes does not do any replication to the server, therefore the server does not see any changes to that value. If you wish to see/learn more, look at the document: Client-Server Runtime | Documentation - Roblox Creator Hub

That’s why data is not being saved.

Still does not work. I used a remote event to make the server update it but it still says I have no data and is saved true on server shutdown

BUT it did throw out an error
"ServerScriptService.SuperDataStore:45 attempt to index boolean with number - Server - SuperDataStore:45"

on line 45 with this code:

		player:WaitForChild("OwnsShovel").Value = data[1] -- line 45
	else
		print("The player has no data!") -- The default will be set to 0	
	end 

EDIT: Nevermind that was old

I did some tinkering and eventually I discovered if I put it in the same datastore as my in-game currency then it saves properly. Maybe that script was different or had interference.

@GE_0E , @gIwwinnq thanks for the help!

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