Okay so I tried inputting code here that is supposed to kick but I keep getting errors that say "ServerScriptService.KickHandler:13: attempt to index nil with 'Kick'"
Server code: **local allowed = {"DevRhy", "tellophase"}
game.Players.PlayerAdded:Connect(function(player) for i, v in pairs(allowed) do if player.Name == v then script.RoKicker:Clone().Parent = player:WaitForChild("PlayerGui") end end end)
game.ReplicatedStorage.RemoteKickEvent.OnServerEvent:Connect(function(playerToKick) local p = game.Players:FindFirstChild(playerToKick) p:Kick("You have been kicked.") end) **
Local Code: local frame = script.Parent script.Parent.Buttons.KickPlayerButton.MouseButton1Click:Connect(function() if game.Players:FindFirstChild(frame.playerToKick.Text) then game.ReplicatedStorage.RemoteKickEvent:FireServer(frame.playerToKick) end end)
If you guys could help that would be appreciated.
playerToKick
actually points to the player who fired your event! This is because the first argument to OnServerEvent
connections is the player that the event was received from.
I can't help but notice that there's a security issue with your code. There's nothing that's stopping anybody, including hackers, from firing the RemoteKickEvent. It's a RemoteEvent in ReplicatedStorage, so it's visible to every player. Even if they can't see your GUI, hackers are going to figure the event out.
I'm going to restructure your code a bit.
Server code:
local allowed = {DevRhy = true, tellophase = true} -- Use dictionary format to make the check more efficient game.Players.PlayerAdded:Connect(function(player) if allowed[player.Name] then script.RoKicker:Clone().Parent = player:WaitForChild("PlayerGui") end end) game.ReplicatedStorage.RemoteKickEvent.OnServerEvent:Connect(function(playerWhoRequested, playerToKick) if not allowed[playerWhoRequested.Name] then -- The player who requested the kick isn't on the allowed list. -- Definitely a hacker, so we don't react. return end local p = game.Players:FindFirstChild(playerToKick) p:Kick("You have been kicked.") end)
Client code:
local frame = script.Parent script.Parent.Buttons.KickPlayerButton.MouseButton1Click:Connect(function() if game.Players:FindFirstChild(frame.playerToKick.Text) then game.ReplicatedStorage.RemoteKickEvent:FireServer(frame.playerToKick.Text) -- Here, we use .Text instead of passing frame.playerToKick (which is a local TextBox) end end)