Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Data Save Doesn't Works, But API's Are Turned ON Help?

Asked by 3 years ago
Edited 3 years ago

ok so i made an datastore service but it doesn't works how it is supposted to.

when i change the value in the console, it just saves it and loads after i rejoin, but when i will change the value with script, for example simple clicking script that adds + 1 to the value, it just doesn't saves value.

here is the video of what it is doing and what not -- https://youtu.be/ktCxZFdqTXk

HERE IS THE CLICK SCRIPT --:

script.Parent.MouseButton1Click:Connect(function(player)

local player = game.Players.LocalPlayer
local clicks = player:WaitForChild("leaderstats"):WaitForChild("clicks")

clicks.Value = clicks.Value +1

end)

HERE IS DATA SAVE SCRIPT--:

local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(plr)

wait()
local plrkey = "id_"..plr.userId

local save1 = plr.leaderstats.clicks

local GetSaved = ds:GetAsync(plrkey)
if GetSaved then
    save1.Value = GetSaved[1]

else
    local NumberForSaving = {save1.Value}
    ds:GetAsync(plrkey, NumberForSaving)

end

end)

game.Players.PlayerRemoving:Connect(function(plr)

ds:SetAsync("id_"..plr.userId, {plr.leaderstats.clicks.Value})
print("saved?")

end)

AND FOR THE LAST SCRIPT HERE IS LEADERSTATS SCRIPT--:

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local clicks = Instance.new("IntValue")
clicks.Name = "clicks"
clicks.Parent = leaderstats
clicks.Value = 0

end)

i have no idea what i am doing wrong, beacause i am begginer and please help me fixing that.

0
Can you re-edit your question and properly put your code in a code block MarkedTomato 810 — 3y
0
Change the value of clicks on the server. The server sees it as 0 while you see it as a different value MarkedTomato 810 — 3y
0
So it does save the clicks but it has a value of 0 just simply the value of clicks in a Script instead of in a LocalScript MarkedTomato 810 — 3y
0
You can get the player by using the PlayerAdded event or with a RemoteEvent. There's a lot of methods of getting the client on the server . The developer wiki can help a lot https://developer.roblox.com/en-us/ MarkedTomato 810 — 3y
0
Thank You Very Much! After Adding Remote And Changing Value With Script Instead Of LocalScript Everything Works MrGeoGamerTV 0 — 3y

Answer this question