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.
LocalScript under KickButton:
game.ReplicatedStorage.AdminEvents.Kick:FireServer(script.Parent.Parent.Player.Text,script.Parent.Parent.Reason.Text,script.Parent.Parent.Error)
end)
KickHandler Script in SSS:
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)
Could you possibly show the full local script?
Just do:
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.
Oops! Here you go:
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.AdminEvents.Kick:FireServer(script.Parent.Parent.Player.Text,script.Parent.Parent.Reason.Text,script.Parent.Parent.Error)
end)
1 Like
You cannot kick from the client. You have to kick from the server.
It works in my game for everyone.
Maybe for you it does. You should always check from the servers view. Not to mention you said you haven’t tested it.
Well I am not on pc right now, but this is very close to the one I have.
What’s going on? You get the error message or nothing happens, when you click que button.
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)