Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why isn't it showing up on the leader stats?

im new to scripting and ive tried to fix the script and watch youtube videos to learn what i did wrong but i cant figure it out.

local datastoreservice = game:GetService("DataStoreService")
local clicksDataStore = datastoreservice:GetDataService("clicks")

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)

this is the part that isn't working and I dont know why.

2 comments

0

Your main problem is use of capitals in game.Players.PlayerAdded. It should be as i just wrote it

0

Whats says the output?

1 answer

--Created by : MarkHunHMD --Put in your ServerScriptService and make a SIMPLE leaderstats script

local dataStoreService = game:GetService("DataStoreService") local leaderstatsDataStore = dataStoreService:GetGlobalDataStore("leaderstats")

local loaded = {}

game.Players.PlayerAdded:connect(function(player) local leaderstats = player:WaitForChild("leaderstats")--Your leaderstats name if player.UserId > 0 and player.Parent then local leaderstatsData = leaderstatsDataStore:GetAsync(player.UserId) if leaderstatsData ~= "Request rejected" then if leaderstatsData then for i, stat in ipairs(leaderstats:GetChildren()) do local value = leaderstatsData[stat.Name] if value then stat.Value = value end end end loaded[player] = true end end end)

game.Players.PlayerRemoving:connect(function(player) local leaderstats = player:FindFirstChild("leaderstats") if leaderstats then if loaded[player] then local leaderstatsData = {} for i, stat in ipairs(leaderstats:GetChildren()) do leaderstatsData[stat.Name] = stat.Value end leaderstatsDataStore:SetAsync(player.UserId, leaderstatsData) end else Instance.new("Folder", player).Name = "leaderstats" end loaded[player] = nil end)

This discussion is preserved as it was. New answers, comments, and votes are closed.