code:
game.ReplicatedStorage.Events.Kick.OnServerEvent:Connect(function(player) local reason = player.PlayerGui.ScreenGui.KickGui.Reason.Text local text = reason local playerID = player.UserId local PLER = player.PlayerGui.ScreenGui.KickGui.Player.Text local y = game.Players:FindFirstChild(PLER) y:Kick(reason) end)
error: 18:20:25.551 - ServerScriptService.Script:7: attempt to index nil with 'Kick'
The reason why this wouldn't work is that the Text Input is client-sided so it won't be able to find the player. What you would have to do use multiple parameters in the firing event, and then call them with OnServerEvent
.
Client:
local submitButton = DefineTheKickButtonHere local playerToKick = DefineTheTextBoxHere local reason = DefineReasonTextBoxHere local event = DefineEventHere submit.MouseButton1Click:Connect(function() event:FireServer(playerToKick.Text, reason.Text) end)
Server:
local event = DefineEventHere event.OnServerEvent:Connect(function(plrWhoFired, plrToKick, reason) if game.Players:FindFirstChild(plrToKick) then game.Players:FindFirstChild(plrToKick):Kick(reason) end end)
Side-Note: the first parameter of the OnServerEvent
event is the player who fired it
There's a better way on doing this:
You wanna use RemoveEvents' argument.
Script on local script:
local kickButton = -- put where is your kick button local playerToKick = -- put where is your player to kick label local kickReason = -- put where is your reason text label local RS = game:GetService("ReplicatedStorage") kickButton.MouseButton1Up:Connect(function() local KickEvent = RS:WaitForChild("KickPlayer") KickEvent:FireServer(playerToKick, kickReason) -- passing out 2 arguments (player and reason) end)
Script on server script:
local RS = game:GetService("ReplicatedStorage") RS.KickPlayer.OnServerEvent:Connect(function(_, player, reason) game.Players:FindFirstChild(player):Kick(reason) end)
Let me know if it works!