Kick message not working

Heres my script:

local gds = ds:GetDataStore("test")

local ts = game:GetService("TextService")

local prefix = "/"

function getPlayer(input)
	input = string.lower(input)
	for _, plr in pairs(game.Players:GetPlayers()) do
		if string.find(string.lower(plr.Name),input) then
			return plr
		end
	end
end

function filter(str,id)
	return ts:FilterStringAsync(str,id):GetNonChatStringForBroadcastAsync()
end

do --commands
	function kick(args)
		kickMsg = "You have been kicked from the server by",args[0].Name.."."
		getPlayer(args[2]):Kick(kickMsg)
	end
	
	function akick(args)
		getPlayer(args[2]):Kick("You have been kicked from the server.")
	end
end

local cmds = {
	["kick"] = kick,
	["akick"] = akick
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		--print(filter(msg,plr.UserId))
		if string.sub(msg,1,1) == prefix then
			msg = string.split(msg,prefix)[2]
			local args = string.split(msg," ")
			args[0] = plr
			if true then--if table.find(cmds,args[1]) then
				if args[1] == "kick" then kick(args) end
			else
				warn("command '"..args[1].."' does not exist!")
			end
		end
	end)
end)```

it works fine except when i do /kick t instead of saying like you have been kicked by Tentoid, it just says you have been kicked by (and then nothing)

ive tried printing the kickmsg and it works as i wouldve expected it just doesnt work when i use it to actually kick.
1 Like

The reason that the kick message is not working as intended is due to the placement of your concatenation operator “…” in function kick(args).

The following line:

kickMsg = "You have been kicked from the server by",args[0].Name.."."

Should be modified to:

kickMsg = "You have been kicked from the server by "..args[0].Name.."."

The reason this works is that the concatenation operator “…” should be used directly between the strings that you want to join together. In your original code, the comma after the first string caused the concatenation operator to be separated from the strings it was intended to join, which subsequently resulted in an incomplete message string. The corrected code provided puts the concatenation operator in the correct place, directly between the strings to be joined.