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

why is my data store script not working when I'm pretty sure everything is right?

Asked by 3 years ago

I have followed tutorials and did everything they told me to do but the script won't work and there is nothing in the output. the only thing I changed is that there isn't a leaderstats folder but it just has a different name.

here is the script

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("DataStore")

local GravelCo = DataStoreService:GetDataStore("GravelCo")

game.Players.PlayerAdded:Connect(function(player)
    local Data = Instance.new("Folder")
    Data.Name = "DataFolder"
    Data.Parent = player

    local GravelColor = Instance.new("IntValue")
    GravelColor.Name = "GravelColor"
    GravelColor.Parent = Data

    local data
    local success, error = pcall(function()
        data = GravelCo:GetAsync(player.UserId.."-GravelColor")
    end)

    if success then
        GravelColor.Value = data
    else
        warn(error)
        print("error saving")
    end

end)

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

    local success, error = pcall(function()
        GravelCo:SetAsync(player.UserId.."-GravelColor",player.DataFolder.GravelColor.Value)
    end)

    if success then
        print("data Saved")
    else
        print("error Saving")
        warn(error)
    end

end)

0
try uploading the game and then playing it, they dont work in studio 0hsa 193 — 3y

1 answer

Log in to vote
0
Answered by
notfenv 171
3 years ago

You don't have to do userid-GravelColor, you can just use the id. Not forcing you to change it but just a reminder.

Also, It might be because your 'error' in pcalls are already a function inside lua. To fix this maybe try doing _error.

Plus, it's an intvalue, not a color/string value. Are you sure you're doing colors by numbers? Have a little debug, see if you can get a result.

game.Players.yasquerda.DataFolder.GravelColor.Value = 1 leave game rejoin game print(game.Players.yasquerda.DataFolder.GravelColor.Value)

Use dev console for this (press F9 and switch to server tab on output). Btw you can't run datastores in studio.

0
Yea, it works. You're probably just assigning strings. notfenv 171 — 3y
Ad

Answer this question