Why is this leaderstat script not working?

Hello, this is one of my first attempts at making a leaderstat script, and I am also quite new to scripting in general. I don’t know why this script isn’t working.

I am trying to make a script, so if they are in a certain group, the leaderstat will display as a short-form name of the group they are in. It is for a military style game.

Here is the script :

local id1 = 11249106
local id2 = 11351445

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder", plr)
	stats.Name = "leaderstats"


	local GroupRank = Instance.new("StringValue", stats)
	GroupRank.Name = "Division"
	GroupRank.Value = plr:IsInGroup(id1)GroupRank.Value = "USAF"
	
	local GroupRank = Instance.new("StringValue", stats)
	GroupRank.Name = "Division"
	GroupRank.Value = plr:IsInGroup(id1)GroupRank.Value = "USMP"
end)

I have looked on the DevForum for solutions, or a leaderstat rank like this, but came out empty. I have tried this many times and always come out unsuccessful. If someone could help me with this script, it would be greatly appreciated.

Are there any errors in the output?

Yeah, it says “ServerScriptService.Script:11: invalid argument #3 (string expected, got boolean)”. I am new to scripting so I don’t really know what this means.

I have amended your code. Hopefully it works. Player:IsInGroup() returns a bool (a true or false).

local id1 = 11249106
local id2 = 11351445

game.Players.PlayerAdded:Connect(function(plr)
	local stats = Instance.new("Folder", plr)
	stats.Name = "leaderstats"

	if plr:IsInGroup(id1) then
	local GroupRank = Instance.new("StringValue", stats)
	GroupRank.Name = "Division"
	GroupRank.Value = "USAF"
	end
	
	if plr:IsInGroup(id2) then
	local GroupRank = Instance.new("StringValue", stats)
	GroupRank.Name = "Division"
	GroupRank.Value =  "USMP"
	end
end)
2 Likes