Help with Scripting Guesses as Points

  1. What do you want to achieve? I want to learn/understand how to script guessing in accordance to points. So pretty much every time someone guesses something right, they get a point on the leaderboard. I also want to know how to save that data so that every time you leave and come back, that data is saved.

  2. What is the issue? I am very new with scripting and I have been trying for the past month to script guessing as points but have not been successful. I’m honestly probably going about it in a way that is making things a whole lot more difficult, but as I stated prior, I really don’t have any experience with scripting so I wouldn’t even know where to begin.

  3. What solutions have you tried so far? I have tried searching on the developers forum and even tried searching on YT but I couldn’t find anything that would help for my particular situation. A lot of tutorials that I found are mainly just touching a part to get points or clicking a part to get points. Never chatting a specific thing to get a point.

So I have three different scripts I’ll include because I’m not sure exactly what I should show in order to get the help I need. The first script is a Global Leaderboard free model that I found. (The Global Leaderboard works fine)

-- [ SETTINGS ] --

local statsName = "Guesses" -- Your stats name
local maxItems = 50 -- Max number of items to be displayed on the leaderboard
local minValueDisplay = 0 -- Any numbers lower than this will be excluded
local maxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local abbreviateValue = true -- The displayed number gets abbreviated to make it "human readable"
local updateEvery = 30 -- (in seconds) How often the leaderboard has to update
local headingColor = Color3.fromRGB(25, 181, 254) -- The background color of the heading

-- [ END SETTINGS ] --




-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. statsName)
local Frame = script.Parent.Frame
local Contents = Frame.Contents
local Template = script.objTemplate

local COLORS = {
	Default = Color3.fromRGB(38, 50, 56),
	Gold = Color3.fromRGB(255, 215, 0),
	Silver = Color3.fromRGB(192, 192, 192),
	Bronze = Color3.fromRGB(205, 127, 50)
}
local ABBREVIATIONS = { "K", "M", "B", "T" }


local function toHumanReadableNumber(num)
	if num < 1000 then
		return tostring(num)
	end
	
	local digits = math.floor(math.log10(num)) + 1
	local index = math.min(#ABBREVIATIONS, math.floor((digits - 1) / 3))
	local front = num / math.pow(10, index * 3)
	
	return string.format("%i%s+", front, ABBREVIATIONS[index])
end

local function getItems()
	local data = DataStore:GetSortedAsync(false, maxItems, minValueDisplay, maxValueDisplay)
	local topPage = data:GetCurrentPage()

	Contents.Items.Nothing.Visible = #topPage == 0 and true or false

	for position, v in ipairs(topPage) do
		local userId = v.key
		local value = v.value
		local username = "[Not Available]"
		local color = COLORS.Default

		local success, err = pcall(function()
			username = Players:GetNameFromUserIdAsync(userId)
		end)

		if position == 1 then
			color = COLORS.Gold
		elseif position == 2 then
			color = COLORS.Silver
		elseif position == 3 then
			color = COLORS.Bronze
		end

		local item = Template:Clone()
		item.Name = username
		item.LayoutOrder = position
		item.Values.Number.TextColor3 = color
		item.Values.Number.Text = position
		item.Values.Username.Text = username
		item.Values.Value.Text = abbreviateValue and toHumanReadableNumber(value) or value
		item.Parent = Contents.Items
	end
end


script.Parent.Parent.Color = headingColor
Frame.Heading.ImageColor3 = headingColor
Frame.Heading.Bar.BackgroundColor3 = headingColor

while true do
	for _, player in pairs(Players:GetPlayers()) do
		local leaderstats = player:FindFirstChild("leaderstats")

		if not leaderstats then
			warn("Couldn't find leaderstats!")
			break
		end

		local statsValue = leaderstats:FindFirstChild(statsName)

		if not statsValue then
			warn("Couldn't find " .. statsName .. " in leaderstats!")
			break
		end

		pcall(function()
			DataStore:UpdateAsync(player.UserId, function()
				return tonumber(statsValue.Value)
			end)
		end)
	end

	for _, item in pairs(Contents.Items:GetChildren()) do
		if item:IsA("Frame") then
			item:Destroy()
		end
	end

	getItems()

	wait()
	Frame.Heading.Heading.Text = statsName .. " Leaderboard"
	Contents.GuideTopBar.Value.Text = statsName
	wait(updateEvery)
end

The second script I’ll show is the standard Leaderstats script that will display the local leaderboard. That one I understand a little bit more because it’s much more simple in nature.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent =player
	
	local Guesses = Instance.new("NumberValue")
	Guesses.Name = "Guesses"
	Guesses.Parent = leaderstats
	Guesses.Value = 0
end)

The last one I am including is the script inside the door. Each door has the same script besides TheCharacter which is different for all since it is a guessing game.

door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	local decal = script.Parent.Decal ----- 
	if (msg == string.lower(thecharacter.Value)) then 
		door.CanCollide = false 
		door.Transparency = 0.7 
		decal.Transparency = 0.7 ----- 
		wait(2) -----------  
		decal.Transparency = 0 ----- 
		door.CanCollide = true 
		door.Transparency = 0 
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

The first script is inside the model in the Workplace. The second script is in the ServerScriptService. And the last one is in the Workplace as well inside a door model.

Any sort of help is appreciated considering I’ve been trying for the past month to find something that works! If you need any screenshots or any other information, I’ll be happy to provide it.