I have created a kick script however it is failing to work.
Localscript:
local DisconnectEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")
script.Parent.MouseButton1Click:Connect(function()
local KickUser = script.Parent.Parent.Parent.PlrName.Text
DisconnectEvent:FireServer(KickUser)
end)
Server script:
Instance.new("RemoteEvent").Parent = game.ReplicatedStorage
game.ReplicatedStorage.RemoteEvent.Name = "Disconnect"
script.Parent = game.ServerScriptService
local DiscEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")
DiscEvent.OnServerEvent:Connect(function(KickUser)
local PlayerKick = game.Players:FindFirstChild(KickUser)
print(KickUser)
if PlayerKick then
print("Final")
PlayerKick:Kick("Administrative Kick: An administrator has removed you from the game")
end
end)
I assume you are making some sort of admin interface. For example, kicking the player directly from a Gui rather than commands. Anyways, rather than having a TextBox object with a name, I would suggest a drop down menu that lists all of the players, so there is no misspelling errors in the process. Secondly, rather than sending the player name through the RemoteEvent, send the player object. Then on the server check if it is a player, kicking that player. Another thing I see, not necessarily the issue, is that you have the “Disconnect” RemoteEvent instanced in a somewhat odd way. I would recommend making the variable: DiscEvent = Instance.new("RemoteEvent")
Then afterward define its parent, name, etc.
Not relevant to the question, but please add protection (even if it just searches for the gui) to the script to keep exploiters from mass kicking (or kicking using this event at all!!) and kick them instead if they abuse remotes.
The UI is stored in the server and is inserted if they are above a certain rank in a group. If a button is pressed when they aren’t above a rank then they’ll get kicked.
script.Parent = game.ServerScriptService
local DiscEvent = game:GetService("ReplicatedStorage"):WaitForChild("Disconnect")
DiscEvent.OnServerEvent:Connect(function(KickUser)
local PlayerKick = game.Players:FindFirstChild(KickUser)
PlayerKick:Kick("Administrative Kick: An administrator has removed you from the game")
end)
remote.OnServerEvent:Connect(function(player, kickuser)
if game.Players:FindFirstChild(kickuser) then
if (rankcheck) then
player:Kick("Administrative Kick: An administrator has removed you from the game")
else
player:Kick("Abusing remotes!")
end
end
end)
(obviously you’d add the rank check, i dont know how you’d do it, but this is only an example.)