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

0

Could you try fixing the thread? It's kind of broken.

0

uh bro use player . userid not playeruserid e

0

i mean like just use player.UserId directly instead of making it a variable

0

theres really no use to have a specific tag like that u just really need their user id

0

i still get the error

0

i fixed it