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

how do i fix this? i have tried for like an hour

Asked by 2 years ago

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'

0
Could you try fixing the thread? It's kind of broken. KingDomas 153 — 2y
0
uh bro use player . userid not playeruserid e TheUltimateTNTFriend 109 — 2y
0
i mean like just use player.UserId directly instead of making it a variable TheUltimateTNTFriend 109 — 2y
0
theres really no use to have a specific tag like that u just really need their user id TheUltimateTNTFriend 109 — 2y
View all comments (2 more)
0
i still get the error agent99919 0 — 2y
0
i fixed it agent99919 0 — 2y

Answer this question