Leaderboard model won't create

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Have my leaderstats show in game.

  1. What is the issue? Include screenshots / videos if possible!

The leaderstats model will not create

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Switching between making a model and a folder.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

My code:

-- CREATE AND STORE STATS IN ROBLOX SERVERS
--=========================================--
-- Create the spot to keep data
local datastore = game:GetService("DataStoreService"):GetDataStore("GCGRs-Speed-Sim-Data")


-- Function for when player joins
function onPlayerEntered(player)
	
	-- Create player stat keys
	local initKey = "user_" .. player.userId .. "_init"
	local stepsKey = "user_" .. player.userId .. "_steps"
	local pointsKey = "user_" .. player.userId .. "_points"
	local speedKey = "user_" .. player.userId .. "_speed"
	local trailKey = "user_" .. player.userId .. "_trail"
	
	-- Create defalts for new players
	if(datastore:GetAsync(initKey) == nil) then
		datastore:SetAsync(initKey, true)
		datastore:SetAsync(stepsKey, 0)
		datastore:SetAsync(pointsKey, 0)
		datastore:SetAsync(speedKey, 1)
		datastore:SetAsync(trailKey, "DefaultTrail")
	end
	
	if(datastore:GetAsync(trailKey) == nil)then
		datastore:SetAsync(trailKey, "DefaultTrail")
	end
	
	-- Load in last saved data
	local init = datastore:GetAsync(initKey)
	local steps = datastore:GetAsync(stepsKey)
	local points = datastore:GetAsync(pointsKey)
	local speed = datastore:GetAsync(speedKey)
	local trail = datastore:GetAsync(trailKey)
	
	--=========================================--
	
	-- Create Leaderboards
	--=========================================--
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local stepsBoard = Instance.new("IntValue")
	stepsBoard.Name = "Steps"
	stepsBoard.Value = steps
	stepsBoard.Parent = leaderstats
	
	
	
	
	
end
--=========================================--
-- Runs onPlayerEntered
game.Players.PlayerAdded:Connect(onPlayerEntered)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

Your probably overloading the script with all that saving and getting data in one function so i sugest you watch gromecode tutoral because it saves abunch of time and works

4 Likes

Try using pcall to fix the issue. Make you you check output if any error messages are printed!

repeat
	task.wait()
	
	local Success, ErrorMessage = pcall(function()
		-- data saving stuff here
	end)

	if ErrorMessage then
		warn(ErrorMessage)
	end
until Success
4 Likes

i might try that but i have been using a codakid video that worked in like 2022 fine.
i will probably try this after contacting codakid.

1 Like

i will probably try this after too.

1 Like

As @MrNobodyDev stated you should not use this much setasync and getasync calls and wrap them in pcall, instead make one table and store every data inside there, after you are done you can save that table to a players key (preferably when they are leaving the game). I suggest learning and using ProfileStore for this as it is a great datastore management module.

1 Like