Group in leaderboard

I have a training place and I want to have it where I can have people put in different groups by a command. When I try to do this I am getting an error saying:
“ServerScriptService:147:attempt to perform arithmetic (add) on string”

Script
local GroupId = 5952287 --GroupId
local MinimumRankToUseCommand = 249 --Rank to use this command


function Check(name)
	name = name:lower()
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Name:lower():sub(1,#name) == name then
			return v
		end
	end
end


game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(GroupId) >= MinimumRankToUseCommand then
		Player.Chatted:Connect(function(Message)
			local Words = string.split(Message, " ")

			if Words[1] == ":Group" then
				local NameOfPlayerToGiveGroup = Words[2]
				local GroupToGive = Words[3]

				local PlayerToGiveGroup = Check(NameOfPlayerToGiveGroup)

				if PlayerToGiveGroup then
					PlayerToGiveGroup.leaderstats.Group.Value = PlayerToGiveGroup.leaderstats.Group.Value + GroupToGive
				end
			end
		end)
	end
end)

Could anyone help me with this? Tell me if you need anymore information.

2 Likes

I think the problem happen because you are trying to add text + text or maybe text + number

2 Likes

Ok. How could I fix this problem?

1 Like

I don’t really know what is the Group.value should be, and what is group to give should be.

2 Likes

Ok. Thank you for the help I will try to figure this out.

1 Like

Just tell me what is these 2 values.

2 Likes
--Group Leaderboard--
local Group = Instance.new("StringValue",leaderstats)
Group.Name = "Group"
Group.Value = "Group"

This is what I have in my leaderboard script.

1 Like

Use the .. operator to concatenate strings.

3 Likes

I don’t really know what is GroupToGive, But if you want to add GroupToGive to Group.Value
Use

..

Like that:

PlayerToGiveGroup.leaderstats.Group.Value = PlayerToGiveGroup.leaderstats.Group.Value .. GroupToGive

If you want space between them:

PlayerToGiveGroup.leaderstats.Group.Value = PlayerToGiveGroup.leaderstats.Group.Value .. " " ..GroupToGive

2 Likes

That works but if I want to change the group it combines them and looks like this.

image

3 Likes

If you don’t want to combine them just do that :

PlayerToGiveGroup.leaderstats.Group.Value = GroupToGive

4 Likes

Ok it is working. Thank you for your help!

3 Likes

Please mark @Omb2a’s solution.