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

This is my first time using data stores an i need a bit of help?

Asked by 3 years ago

Every time I try to save the data it says the error message and UserId is not a valid member of RBLXScriptSignal and when I try to save it when leaving it says ServerScriptService.Data Stores:28: attempt to index number with 'Value'

player = game.Players.PlayerAdded
local DataStoreService = game:GetService("DataStoreService")

local GravelColor = DataStoreService:GetDataStore("GravelColor")

local ColorOfG = game.ReplicatedStorage.Color

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

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

    if success then
        GravelColor = data
        ColorOfG = GravelColor
    else
        print("There was an error when getting your Data")
        warn(errorMesage)
    end

end)

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

    local success, errorMesage = pcall(function()
        GravelColor:SetAsync(player.UserId.."-color", ColorOfG.Value)
    end)

    if success then
        print("Player Data Succesfully Saved")
    else
        print("There was an error when saving Data")
        warn(errorMesage)
    end
end)

while true do
    wait(20)
    local success, errorMesage = pcall(function()
        GravelColor:SetAsync(player.UserId.."-color", ColorOfG.Value)
    end)

    if success then
        print("Player Data Succesfully Saved")
    else
        print("There was an error when saving Data")
        warn(errorMesage)
    end
end

Sorry if this is really obvious or something this is my first time using data stores

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

ColorOFG is a number because you set it to a datastore in line 17

ColorOFG = GravelColor

GravelColor is the same thing as GravelColor:GetAsync(player.UserId .. "-color") or the same thing as player.UserId so it's a number instead of the instance in ReplicatedStorage. To fix it, do this on the playerremoving event:

game.Players.PlayerRemoving:Connect(function(player)
    ColorOFG = game.ReplicatedStorage.Color
    -- code to save here
end

You can accept my answer if it works!

Ad

Answer this question