this is my script local dataStoreService = game:GetService("DataStoreService") local clicksDatastore = dataStoreService:GetDataStore("Clicks1")
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats"
local clicks = Instance.new("IntValue",leaderstats)
clicks.Name = "Clicks"
clicks.Value = 0
local playerUserId = "player_"..player.UserId
-- Loading Data
local clicksdata
local success, errormessage = pcall(function()
clicksdata = clicksDatastore:GetAsync(playerUserId)
end)
if success then
clicks.Value = clicksdata
end
end)
-- saving data game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "player_"..player.UserId
local clicksValue = player.leaderstats.Clicks.value
local success, errormessage = pcall(function()
clicksDatastore:SetAsync(playerUserId, clicksValue)
end)
end)
game:BindToClose(function(player) local playerUserId = "player_"..player.UserId
local clicksValue = player.leaderstats.clicks.value
local success, errormessage = pcall(function()
clicksDatastore:SetAsync(playerUserId, clicksValue)
end)
end)
and this is the error ServerScriptService.leaderstats:37: attempt to index nil with 'UserId'

6 comments
Could you try fixing the thread? It's kind of broken.
uh bro use player . userid not playeruserid e
i mean like just use player.UserId directly instead of making it a variable
theres really no use to have a specific tag like that u just really need their user id
i still get the error
i fixed it