Support on error with values

Hello,

So I am trying to create a point system so when you use a command you can give someone one point. Here is my script below if anyone could help. I am also not sure what value to use as I want there to be text and numbers on the same value (0 = trainee N/A = MR+).

game.Players.PlayerAdded:Connect(function(plr)
	local Leaderstats = Instance.new("Folder", plr)
	Leaderstats.Name = "leaderstats"
	
	points = Instance.new("StringValue", Leaderstats)
	points.Name = "Points"
	
	local rank = Instance.new("StringValue", Leaderstats)
	rank.Name = "Lighthouse Rank"
	
	rank.Value = plr:GetRoleInGroup (6559630)
	
	if plr:GetRankInGroup (6559630) == 5 then
		points.Value = 0
	elseif plr:GetRankInGroup (6559630) == 255 and 254 then
		points.Value = "N/A"
	end
end)

local commands = {}

local prefix = "!"

local player = game.Players

local function findPlayer(name)
	for i, player in pairs(game.Players: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) 
	
		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

Attempt to add Instance and number means try trying to add a number and an object together, meaning it will error. Very simple solution: add .Value to the end to reference the Values Value property.

I also noticed inside your PlayerAdded function your setting ‘points’ to a StringValue, meaning that attempting t add the value of a stringvalue will error. I recommend you change that to a NumberValue.

also, += exists so instead of doing foo = foo + 1, you can just do foo += 1.

Yea I know. Do you know how I could then make it so that some ranks in a group have N/A next to their points and some have 0 as they are both different.

Edit: I am going to add a if statement to stop people being able to give MR+ (the ones with the string) as they don’t need to be able to get points.