Script not kicking player

Hello, I am trying to make a admin panel. The issue is my script won’t kick players when it should and is not giving errors.

Client Side:
local PanelFrame = script.Parent.PanelFrame

local AnnouncementText = script.Parent.PanelFrame.AnnouncementText

local UsernameText = script.Parent.PanelFrame.UsernameText

local ReasonText = script.Parent.PanelFrame.ReasonText

local SendAnnouncement = script.Parent.PanelFrame.SendAnnouncement

local Kick = script.Parent.PanelFrame.Kick

local Ban = script.Parent.PanelFrame.Ban

local Unban = script.Parent.PanelFrame.Unban

local Warn = script.Parent.PanelFrame.Warn

local GroupRank = script.Parent.PanelFrame.GroupRank

local Players = game:GetService(“Players”)

local LocalPlayer = Players.LocalPlayer

local KickInfo = game.ReplicatedStorage:WaitForChild(“Kick”)

local WarnInfo = game.ReplicatedStorage:WaitForChild(“Warn”)

local KickUsername = UsernameText.Text

local KickReason = ReasonText.Text

local Group = “10880254”

GroupRank.Text = LocalPlayer:GetRoleInGroup(Group)

Kick.MouseButton1Click:Connect(function()

KickInfo:FireServer(KickUsername, KickReason)

end)

Server Side:
local Kick = game.ReplicatedStorage:WaitForChild(“Kick”)

local Warn = game.ReplicatedStorage:WaitForChild(“Warn”)

Kick.OnServerEvent:Connect(function(Username, Reason)

local PlayerToKick = Username

PlayerToKick = game.Players:FindFirstChild(PlayerToKick)

if not PlayerToKick or not PlayerToKick:IsA(“Player”) then

return

end

PlayerToKick:kick(’\nHSH - Disconnected\nYou have been kicked from the server\nReason:\n’…Reason)

end)

This cannot be a string the function only takes in a numerical value, take the quotation marks off then try again

if it doesn’t work just msg me

@Hydrollo Didn’t work (30 30)

Also try this for the server script

local Kick = game.ReplicatedStorage:WaitForChild('Kick')
local Warn = game.ReplicatedStorage:WaitForChild('Warn')

Kick.OnServerEvent:Connect(function(Username, Reason)
	local PlayerToKick = game.Players:FindFirstChild(Username)

	if not PlayerToKick or not PlayerToKick:IsA('Player') then
		return
	end

	PlayerToKick:kick('\nHSH - Disconnected\nYou have been kicked from the server\nReason:\n'..Reason)
end)

Didn’t work (30 30 30 30 30 30)

just saw that your Click event was sending 2 paramaters but it only needs 1 because by default when firing a FireServer the first paramater of the received function is always the player

Kick.MouseButton1Click:Connect(function()

KickInfo:FireServer(KickReason)

end)

Also the changes i mentioned may not be the answer your looking for but they may help in future problems

try doing this

Kick.MouseButtion1Click:Connect(function()
local UserName = UsernameText.Text
local Reason = ReasonText.Text

KickInfo:FireServer(UserName,Reason)

end)

also the arguments for the server should be player, Username , Reason
due to the first argument always being the player on the server

Error:
MouseButtion1Click is not a valid member of TextButton “Players.bodietwenty20.PlayerGui.ManagementPanel.PanelFrame.Kick” - Client - LocalScript:25
09:41:11.836 Stack Begin - Studio
09:41:11.836 Script ‘Players.bodietwenty20.PlayerGui.ManagementPanel.LocalScript’, Line 25 - Studio - LocalScript:25
09:41:11.836 Stack End - Studio

its spelt wrong

try the one i sent for the fire event you dont need all the extra stuff

I made a spelling mistake lol

Kick.MouseButton1Click:Connect(function()
local UserName = UsernameText.Text
local Reason = ReasonText.Text

KickInfo:FireServer(UserName,Reason)

end)

Not sending any error but still doesn’t work.

can you send screenshots of both the local script and server script, maybe there was a mistyping in the code you sent.

Sure(303030303030303030303030303)


Kick.OnServerEvent:Connect(function(Player,Username, Reason)
   local PlayerToKick = game.Players:FindFirstChild(Username)

if PlayerToKick and PlayerToKick:IsA("Player") then
   PlayerToKick:Kick(tostring(Reason))
    print("Passed")
 end
end)

Thank you so much! It worked! (30)

Epic,make sure to mark my post as the solution!
I now will disappear

Ok i went through and fixed everything on it

local PanelFrame = script.Parent.PanelFrame

local AnnouncementText = script.Parent.PanelFrame.AnnouncementText

local UsernameText = script.Parent.PanelFrame.UsernameText

local ReasonText = script.Parent.PanelFrame.ReasonText

local SendAnnouncement = script.Parent.PanelFrame.SendAnnouncement

local Kick = script.Parent.PanelFrame.Kick

local Ban = script.Parent.PanelFrame.Ban

local Unban = script.Parent.PanelFrame.Unban

local Warn = script.Parent.PanelFrame.Warn

local GroupRank = script.Parent.PanelFrame.GroupRank

local Players = game:GetService('Players')

local KickInfo = game.ReplicatedStorage:WaitForChild('Kick')

local WarnInfo = game.ReplicatedStorage:WaitForChild('Warn')

local KickReason = ReasonText.Text

local PlayerTokick = Players:FindFirstChild(UsernameText.Text)

local Group = 10880254

GroupRank.Text = game.Players.LocalPlayer:GetRoleInGroup(Group)

Kick.MouseButton1Click:Connect(function()

KickInfo:FireServer(KickReason, PlayerTokick)

end)

--ServerSide

local Kick = game.ReplicatedStorage:WaitForChild('Kick')

local Warn = game.ReplicatedStorage:WaitForChild('Warn')

Kick.OnServerEvent:Connect(function(Player, Reason, PlayerToKickName)

local PlayerToKick = game.Players:FindFirstChild(PlayerToKickName)

if not PlayerToKick or not PlayerToKick:IsA('Player') then

return

end

PlayerToKick:kick('\nHSH - Disconnected\nYou have been kicked from the server\nReason:\n'..tostring(Reason))

end)

This should fix your problem and many others that were in the code

Thank you! (30 30 30 30 30 30 30)

2 Likes

id also suggest filtering the reason