I've been making a datastore, where I store my data, however, whenever I use 'UserId' it outputs an error. I've seen quite a few posts, and this problem has been occuring mostly to datastores. Are there any solutions? If so, please comment or answer! :)
local DataStoreService = game:GetService("DataStoreService") -- Accessing the targetted service
local PointsStore = DataStoreService:GetDataStore("PointsStore") -- Creating a DataStore; progress will be deleted if key is changed
local Players = game:GetService("Players") -- Accessing the targetted service
function onPlayerAdded(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue",leaderstats)
Points.Name = "Points"
local Rank = Instance.new("StringValue",leaderstats)
Rank.Name = "Rank"
if player:IsInGroup(5265499) then
Rank.Value = player:GetRoleInGroup(5265499)
end
local data
local success, errorMessage = pcall(function()
data = PointsStore:GetAsync("clientPoints"..player.UserId)
end)
if success then
Points.Value = data
else
print("There was an error whilst recieving the Client's Data Key")
warn(errorMessage)
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
function onPlayerRemove(player)
local success, errorMessage = pcall(function()
PointsStore:SetAsync("clientPoints"..player.UserId,player.leaderstats.Points.Value)
end)
if success then
print("Successfully recieved Client's Data Key.")
else
print("There was an error whilst recieving the Client's Data Key")
warn(errorMessage)
end
end
game.Players.PlayerRemoving:Connect(onPlayerRemove)
-- Used for servers which have been shutdown or connection problems
game:BindToClose(function()
for _,players in pairs(game.Players:GetChildren()) do
onPlayerRemove()
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getPoints = ReplicatedStorage:WaitForChild("getPoints")
function getPoints(player)
print(PointsStore:GetAsync(player.UserId.."clientPoints",player.leaderstats.Points.Value))
end
getPoints.OnClientInvoke = getPoints()

1 comment
I'm so sorry! It didn't work, perhaps you have any leftover solutions for me to try out? Thanks for helping, though! :D