Boombox won't give when /boombox [playername] is sent in chat

I’ve been trying to write up a script that awards a player a boombox when a certain rank in the group or above types /boombox user, I’ve looked around the devforum and the devhub and thrown together something but it doesn’t work at all. No errors print in the console.

I’m probably overlooking something so basic but for the life of me I can’t figure it out, I’d appreciate any help.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local GroupId = 11951218
local MinimumRank = 253

local BadgeId = 2124808396

local BoomboxModel = game.ServerStorage:WaitForChild("Gears").BlackstoneBoombox

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(msg)
		if Player:GetRankInGroup(GroupId) >= MinimumRank then
			if msg:sub(1,7) == "/boombox " then
				local PlayerToBeAwarded = game.Players:FindFirstChild(msg:sub(8))
				if PlayerToBeAwarded then
					game:GetService("BadgeService"):AwardBadge(PlayerToBeAwarded.UserId, BadgeId)
					BoomboxModel:Clone().Parent = PlayerToBeAwarded.Backpack
				end
			end
		end
	end)
end)
1 Like

The problem is that the string you are trying to validate with msg:sub(1, 7) is 9 characters long,

change that line to

if msg:sub(1, 9) == "/boombox " then

Then the following line, defining the PlayerToBeAwarded must be altered, as the players name will start from the 10th index within the string (as "/boombox " is 9 characters long)

local PlayerToBeAwarded = game.Players:FindFirstChild(msg:sub(10))
3 Likes

Thanks so much! Really appreciate it man.

1 Like