Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

RemoteEvent that's supposed to kick a player not working?

Theres a RemoteEvent in workspace called "Kick", this is the script that's inside of it:

script.Parent.OnServerEvent:connect(function(p)
game.Players:findFirstChild(p):Kick()
end)

Here's the localscript that calls it:

workspace.Kick:FireServer(game.Players.LocalPlayer.Name)

and it's not working.

2 answers

Knock knock
Who's there?

OnServerEvent takes the Player as the first argument, meaning that sending the Player you're trying to kick is a little redundant - If you want to just kick the LocalPlayer, it's simple enough:

Server

local Players = game.Players
-- This is the fun bit. Watch this.
local Kick = (Players:GetChildren()[1] or Players.PlayerAdded:wait()).Kick
script.Parent.OnServerEvent:connect(Kick)

Client

workspace.Kick:FireServer()

If you're wondering how the server script works, it simply gets a random player or the first player to join and gets the Kick function from it. Because the OnServerEvent always returns the player who used it, that gets passed straight to Kick and they get booted.

2 comments

0

It's for an admin script, I wanna be able to go workspace.Kick:FireServer("playername")

0

Well you don't want to do it from the client, that's for sure.

Normally, to kick a player from the game it has to be done server sided.

Check the notes in this link: http://wiki.roblox.com/index.php?title=API:Class/Player/Kick

The most common way to do what you trying to do is like so:

Server Script

local remoteevent = Instance.new("RemoteEvent", workspace) -- Create the remote event server sided.
remoteevent.Name = "Kick" -- Name the remote event so it's identificable.

remoteevent.OnServerEvent:connect(function(Player, Request) -- Do an On Server Event.
	if Request == "KickThis" then -- Send a Request to the server and if it's equal to it.
		Player:Kick() -- Kick the player.
	end
end)

Local Script

local remoteevent = workspace:WaitForChild("Kick") -- Wait for the remote event incase it doesn't.

remoteevent:FireServer("KickThis") -- Send the Request String to the server.

This discussion is preserved as it was. New answers, comments, and votes are closed.