Datastore save value in client not in server

Hi devs,
I have a problem with my datastroe.
The value saved on studio on the client and when I retest the game the value is saving, but the value its ZERO when I switch to the server.
I tested a lot and different Datastorage.

I have part in workspace with a script. When the value is >5 then part destroy. When the value is on client bigger then 5 is doenst work, but when I change the value at 6 on the server the part is destroyed.

Please help me so I can finish my game.

Thx

The script in the part in workspace:

local owner = script.Parent.Parent.Parent.Parent.TycoonInfo:FindFirstChild(“Owner”)
local plr = owner.Value
local star = plr:WaitForChild(“StarsTest”).StarsCollected
while true do
wait(.1)

if star.Value > 5 then -- 6 Stars
	print("OPEN")
	script.Parent:Destroy()
	break
end

end

So if I understand you correctly, you are attempting to read a value that‘s saved on the client on the server.

Use RemoteEvents to transfer data from the client to the server

Hi @CriCret_LTD !

A Value instance (i.e. a StringValue, NumberValue, etc.) is not the same as a Datastore. Datastores are a bit more complex, and you can read more about them here: Data Stores | Roblox Creator Documentation

What you’re also running into is the difficulties surrounding Roblox’s client-server model. There’s loads of information here: Client-Server Model | Roblox Creator Documentation, but in short:

When something changes on the server, it changes on all of the clients. This is known as replication. However, when something changes on a client, it doesn’t change on the server. Otherwise, a hacker would be able to change their own client (for example, giving themselves a load of money), replicate that change to the server, and then also replicate those changes to all the other clients.

This would be a massive security risk, as there is nothing you can do to stop a hacker from changing their client.

The way this is impacting you is that you’re changing the StarsCollected value on the client (anything in the Workspace is on the client), which doesn’t replicate to the server (for the security reasons discussed earlier), which is why on the server nothing appears to be changing.

1 Like

I tried but its hard. A another question, how can i make a part in workspace destroyed when a value rich foe example “5” stars on leaderstat? Because the textlebal with the star value works fine.

local plr = game.Players.LocalPlayer

while true do

wait(0.1)

script.Parent.Text = plr:WaitForChild(“Stars”).Value…""

end

and thx for your helps