I am trying to script a button for a gui that Kicks people. Sound simple enough, right? Well, I can’t figure out what the problem is here and I have tried changing multiple things about the script. If anyone can help me, that would be great.
game.ReplicatedStorage.AdminEvents.Kick.OnServerEvent:Connect(function(plr,PlayerName,Reason,Error)
if game.Players:FindFirstChild(PlayerName) == nil then
Error.Visible = true
wait(3.5)
Error.Visible = false
else
local NeedsKicking = game.Players:FindFirstChild(PlayerName)
NeedsKicking:Kick("You have been kicked from the game by " .. plr .. ". Reason: "..Reason)
end
end)
local trigger = script.Parent
local target = script.Parent.Parent.Target.Text -- player name whom you want to kick
local players = game:GetService("Players")
local reason = script.Parent.Parent.Reason.Text
trigger.MouseButton1Click:Connect(function)
players[target]:Kick(reason)
end)
Havent tested this since im not on my pc.
Have a good day!
No Remotes needed at all.
Any errors? Reply to this and I’ll fix them, I am just not on pc right now to test.
Your local script and server script needs some fixes. Try this local script below:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KickEvent = ReplicatedStorage:WaitForChild("AdminEvents").Kick
local KickButton = script.Parent
local PlayerToKick = KickButton.Parent:WaitForChild("Player")
local Reason = KickButton.Parent:WaitForChild("Reason")
local Error = KickButton.Parent:WaitForChild("Error")
KickButton.Activated:Connect(function()
for i, plr in pairs(game.Players:GetPlayers()) do
if PlayerToKick.Text == plr.Name then -- to check if player exists
KickEvent:FireServer(PlayerToKick.Text, Reason.Text) -- fires event
else -- otherwise
Error.Visible = true -- error message will show
wait(3.5)
Error.Visible = false
end
end
end)
Then in your Server Script, use this code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KickEvent = ReplicatedStorage:WaitForChild("AdminEvents").Kick
KickEvent.OnServerEvent:Connect(function(player, PlayerToKick, Reason)
if game.Players:FindFirstChild(PlayerToKick) then -- if player to kick exists
-- Kicks player
game.Players:FindFirstChild(PlayerToKick):Kick("You have been kicked from the game by " ..player.Name.. ". Reason: "..Reason)
end
end)