Find a string --------

I’m trying to make a ban script (I don’t want a ban command or anything like that) where I can gather the player’s userId and the reason, but I don’t know how to do it.

local ban = {
	[1] = "reason"
}

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(ban, plr.UserId) then
		plr:Kick("Club Trendi    You have been banned. Reason: array here")
	end
end)
1 Like
local BannedPlayers = {
	[1] = "reason"
}

game.Players.PlayerAdded:Connect(function(Player)
	for UserId, Reason in pairs(BannedPlayers) do 
		if Player.UserId == UserId then 
			Player:Kick("Club Trendi    You have been banned. Reason: ".. Reason)
		end
	end
end)
1 Like

You can use string.split for this.

-- guessing that the format will be ':ban [player id] [reason]'

local PS = game:GetService("Players")

PS.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		local split = string.split(message, " ")
		local command, id, reason = split[1], split[2], split[3]
	end)
end)

I did mention that I didn’t want a ban command but thanks I guess?

1 Like

Oh, my bad.

local PS = game:GetService("Players")
local ban = {
	[13131313] = "reason"
}

PS.PlayerAdded:Connect(function(plr)
	if ban[plr.UserId] then
		plr:Kick("Club Trendi    You have been banned. Reason: " .. ban[plr.UserId])
	end
end)
2 Likes
local ban = {
	[(userId here)] = {
            ["reason"] = "reason here"
    }
}

game.Players.PlayerAdded:Connect(function(plr)
	if ban[plr.UserId] then
		plr:Kick("Club Trendi    You have been banned. Reason:"..ban[plr.UserId]["reason"])
	end
end)

you could also do something like

local ban = {
	[(userId here)] = {
            ["reason"] = "reason here",
            ["admin"] = "achdef"
    }
}

game.Players.PlayerAdded:Connect(function(plr)
	if ban[plr.UserId] then
		plr:Kick("Club Trendi    You have been banned by"..ban[plr.UserId]["admin"]..". Reason:"..ban[plr.UserId]["reason"])
	end
end)

that’s actually good thank you so much