Leader stats/points add system

Good afternoon/morning,

So I am trying to script a point system so that when you use a command it will add one point on. I am getting a error and think there is more then one thing wrong so if anyone could help me sort out the error and make sure the script will work that would be great.

local commands = {}

local prefix = "!"

local player = game.Players

local function findPlayer(name)
	for i, player in pairs(game.Player:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player
		end
	end
	return nil
end

commands.test = function(sender, args)
	
	
	for i,playerName in pairs(args)do
		print(playerName)
	end
	local playertogivepoints = args[1]
	
	if playertogivepoints then
		local plrtogive = findPlayer(playertogivepoints)
		
		local points = game.Players.plrtogive.leaderstats.Points
		
		if plrtogive then
			points = points + 1
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message,recipient)
		message = string.lower(message)
		
		local splitstring = message:split(" ")
		local slashcommand = splitstring[1]
		local cmd = slashcommand:split(prefix)
		local cmdName = cmd[2]
		
		if commands [cmdName] then
			local args = {}
			for i = 2, #splitstring, 1 do
				table.insert(args, splitstring[i])
			end
			commands[cmdName](player, args)
		end 
	end)
end)

image

1 Like

game.Players is a service, with the S. You forgot the S

1 Like

Um what do you mean S ?? I don’t understand

They meant the letter “S,” you must’ve forgotten it in one of the lines.

Edit

image

You forgot it in this line:

for i, player in pairs(game.Player:GetPlayers()) do

How would I fix this error. It is basicly were I need to get the leader stats and change it.
image

@myaltaccountsthis

Can you provide the line this error is coming from?

Do plrtogive.leaderstats.Points as plrtogive is already the player.

also for this part, make it points.Value += 1
+= is just short for points.Value = points.Value + _

I am getting another error now I did what you told me to.
image

It’s on the same part of script

I suggest adding a WaitForChild()
Such as:

plrtogive:WaitForChild("leaderstats").Points

Did you ever make a folder under the player called “leaderstats”?
Edit: If not, put this after game.Players.PlayyerAdded:Connect()

local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"

I have a script that makes it when the player joins for the leaderstats

did you name the folder “leaderstats” because it has to be case-sensitive and the exact name

Is this for saving leaderstats?

no, datastore is another level

Not saving just to add on a data to the leaderstat

also look what i said above about changing the property “Value” of points