I’m making an administration panel for a game, and there’s a kick part on there. Everything is working fine except for the reason for the kick. I tried adding a table so that stuff will pop up when the player is kicked; however, it just pops up as “{}”
I’m rather new to some of this stuff, so I’m unsure what is wrong with my code. I am using a remote event with this too.
LOCAL SCRIPT - KICK HANDLER
local remoteevent = game:GetService("ReplicatedStorage"):FindFirstChild("Events"):WaitForChild("Kick")
script.Parent.MAIN.KICK.MouseButton1Click:Connect(function(player)
local playername = script.Parent.PLAYERNAME.Text
local reason = script.Parent.REASON.Text
local kickinfo = {
["Administrator"] = game.Players.LocalPlayer.Name,
["UserID"] = playername.UserId,
["Reason"] = reason,
["Time"] = os.time(),
}
if playername == "" then
script.Parent.PLAYERNAME.BorderColor3 = Color3.fromRGB(255, 0, 0)
wait(1.5)
script.Parent.PLAYERNAME.BorderColor3 = Color3.fromRGB(27, 42, 53)
else
if reason == "" then
reason = "N/A"
remoteevent:FireServer(playername, kickinfo)
script.Parent.Visible = false
wait(2.5)
script.Parent.PLAYERNAME.Text = ""
script.Parent.REASON.Text = ""
else
print("Kicking "..playername.." for: "..reason..".")
remoteevent:FireServer(playername, kickinfo)
script.Parent.Visible = false
wait(2.5)
script.Parent.PLAYERNAME.Text = ""
script.Parent.REASON.Text = ""
end
end
end)
SERVER SCRIPT
local Administration = {"Comqts"}
local remoteevent = game:GetService("ReplicatedStorage"):FindFirstChild("Events"):WaitForChild("Kick")
remoteevent.OnServerEvent:Connect(function(player,playername,kickinfo)
if table.find(Administration, player.Name) then
for _,Players in pairs(game.Players:GetPlayers()) do
if Players.Name == playername then
Players:Kick(kickinfo)
end
end
else
player:Kick("You are not authorized to use this command.")
end
end)
Firstly, you can’t call UserId on text. UserId is exclusive to player objects. You can get the player’s name through player.Name, there is no need to pass that as a parameter.
As pointed out, you can’t send a table as the Kick Message parameter. It’ll most likely error. Speaking of errors, do you have any errors in the output? There certainly should be one for the UserId on the text, but what other ones are there?
They did this by using table.concat. They used the special newline character, \n, which puts the text on a new line.
You can achieve the same by doing this:
local Administration = {"Comqts"}
local remoteevent = game:GetService("ReplicatedStorage"):FindFirstChild("Events"):WaitForChild("Kick")
remoteevent.OnServerEvent:Connect(function(player,playername,kickinfo)
if table.find(Administration, player.Name) then
for _,Players in pairs(game.Players:GetPlayers()) do
if Players.Name == playername then
Players:Kick(table.concat(kickinfo,"\n"))
end
end
else
player:Kick("You are not authorized to use this command.")
end
end)