What do you want to achieve? Kick The Player By Inputting There Name Into A Text Box, then pressing a button to fire a RemoteEvent, which then kicks the given player.
What is the issue? Script Not Working, No Errors In Output, Debug print() statements not running.
What solutions have you tried so far? Changing my scripts and looking on the devforum
Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local btn = script.Parent --Gui Button Which Fires The Function
local textbox = script.Parent.Parent.KickInput --Gui Textbox where you Input Player Name
local RemoteEvent = ReplicatedStorage.KickEvent --The RemoteEvent
btn.MouseButton1Up:Connect(function()
local text = textbox.Text
if Players:FindFirstChild(text) then
RemoteEvent:FireServer(text)
end
end)
Script
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
RemoteEvent.OnServerEvent:Connect(function(plr, text)
print(text)
Players:FindFirstChild(text):Kick("Kicked By An Admin")
print("Kicked")
end)
I will also add that this is my time using RemoteEvents, so I might have made a simple mistake.
local Players = game:GetService("Players")
local remoteEvent = game:GetService("ReplicatedStorage").KickEvent
local button = script.Parent
local kickInputBox = script.Parent.Parent.KickInput
button.MouseButton1Click:Connect(function()
local plrName = kickInputBox.Text
if Players:FindFirstChild(plrName) then
remoteEvent:FireServer(Players:FindFirstChild(plrName))
end
end)
Server Script:
local remoteEvent = game:GetService("ReplicatedStorage").KickEvent
remoteEvent.OnServerEvent:Connect(function(_,plrToKick)
plrToKick:Kick("Kick message goes here!")
end)
I tested this in studio and it worked for me. If you’re still having issues, try printing various test messages to ensure that the remote event is firing correctly, and plrToKick is the correct player.
Hope this helps!
Edit:
If you don’t want typing in the player’s name to be case-sensitive, you’ll need to loop through all the players like this:
-- Inside button.MouseButton1Click
local plrName = kickInputBox.Text:lower()
for i, plr in pairs(Players:GetPlayers()) do
if plr.Name:lower() == plrName then
remoteEvent:FireServer(plr)
return -- No need to keep looping, so end the function here
end
end
No need to think that way instead treat this as an opportunity to learn/try things besides validating the person firing the remote is quite simple
Event.OnServerEvent:Connect(function(Who, Target)
if Who.UserId ~= YourUserId then
Who:Kick("The last time i checked my name wasn't "..Who.Name..".")
return --Ends the function
end
Target:Kick("You were kicked by an admin.")
end)
Also if you’re planning on having many remotes for various actions that requires conditions to be usable like having an item equipped i recommend using codes rather than describing what went wrong.
Who:Kick("Invalid remote request. [Q]") --Q isnt a key its a number in qwerty you'd go q w e r t etc. all the way to the last key then start going QQ QW QE QR QT QY etc. then WQ WW WE WR its easy to keep track of
Doing this will make things harder to understand for exploiters while still keeping it relatively possible to keep track of for you in case an actual bug were to accur and kick an innocent player.
i made a slight adjustment to the local script and this should check if the player is an admin or not
local button = script.Parent
local Players = game:GetService("Players")
local Admins = {1,2,3} -- Put user id's here and seperate them with ","
local plr = Players.LocalPlayer
button.MouseButton1Down:Connect(function()
if table.find(Admins,plr.UserId) then -- checks if the player's user id matches with one from the table
-- Script here
else
print("Player's userId does not match")
end
end)
table.find() can be slow depending on how many ids you’re working on, use this instead!
local button = script.Parent
local Players = game:GetService("Players")
local Admins = {
[PlayerId] = true,
[AnotherPlayerId] = true
} -- Put user id's here and set em to true
local plr = Players.LocalPlayer
button.MouseButton1Down:Connect(function()
if Admins[plr.UserId] then -- checks if the player's user id matches with one from the table
-- Script here
else
print("Player's userId does not match")
end
end)
Tho ideally you shouldn’t even be loading any admin scripts to non-admin users and all admin checks should be done on server side since its possible to decompile lua scripts to a certain extent.