so I have made this script but I want it to get executed whenever I type ‘!ban username reason’
game.Players.PlayerAdded:Connect(function(plr, reason)
plr.Chatted:Connect(function(Message)
if plr:GetRankInGroup(GroupID) >= HRRank and Message == ‘!ban’…plr.Name then
end
end)
end)
You’re not parsing the message correctly. You’re trying to concatenate the string with the player’s name but you’re only indexing the chat speaker’s name and not every other player, plus you’re not accounting for the reason argument.
Here’s an example I wrote of how you could parse the message. It isn’t the best solution but it should point you in the right direction.
game.Players.PlayerAdded:Connect(function(plr, reason)
plr.Chatted:Connect(function(Message)
local ToBanUsername = Message:split(" ")[1] -- Calls string.split on the message which returns each group of characters separated by a space in a table and indexes the first group of characters. Note: this does not account for usernames with spaces.
local ToBan = game.Players:FindFirstChild(ToBanUsername)
if ToBan then -- Checks if the ban player argument is valid by checking for the player to ban's player instance
local Reason = Message:sub(#PlayerToBan, #Message) -- Calls string.sub on the message which returns the characters between the 1st and 2nd arg index of the string
if not #Reason > 1 then -- If no reason is supplied, make the reason generic
Reason = "You have been banned."
end
ToBan:Kick(Reason) -- Kicks the player with the reason
-- Now all you have to do is datastore the banned player with the reason so they can't rejoin
end
end)
end)