I have an admin GUI stored in server storage, to keep it safe from exploiters. When a player joins, my system figures out the roles, then clones it into my gui. In that admin GUI, there is a simple kick script. (The event is in the GUI) ~~~~~~~~~~~~~~~~~
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plrName, Reason, returnPlr) plrName = tostring(plrName) Reason = tostring(Reason) local Success, Error = pcall(function() local plrID = game.Players:GetUserIdFromNameAsync(plrName)
local plr = game.Players:GetPlayerByUserId(plrID) if plr then print(plr.Name) plr:Kick(Reason) script.Parent.Callback:FireClient(returnPlr, "Successfully kicked "..plrName) else script.Parent.Callback:FireClient(returnPlr, "Invalid") end end) if not Success then script.Parent.Callback:FireClient(returnPlr, "Error | Devs Check Console") error(Error) end
end) ~~~~~~~~~~~~~~~~
What the event returns is the player's name and reason. These all return the correct things. But no matter what I do, I cannot kick another player. It kicks me for an unspecified reason. I came with no errors, it returns the plrname and reason correctly. What am I doing wrong?
Thanks in advance
Signed - Cheslin23t
It may not work because the sever, even though it can read server storage, it does not run from server storage, try switching to server script service and it may work.
Your script is not safe from exploiters.
None of those answers answered. I forgot to read the docs! If firing from the client, when getting it from the server, it also returns the player who sent it