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

my data doesn't saves when value gets changed by script. help?

Asked by 3 years ago
Edited by JesseSong 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.

1 answer

Log in to vote
0
Answered by 3 years ago

Go to your game settings, then go to security, and make sure "Enable Studio Access to API Servers" is turned on - if this is off you will be unable to access datastores from Roblox Studio.

0
it is currently turned on. but it doesn't works. MrGeoGamerTV 0 — 3y
0
i edited my description and added video about it. please check it and maybe you can find out what am i doing wrong MrGeoGamerTV 0 — 3y
Ad

Answer this question