I have a gui that kicks a player, but i want to know who kicked the player so i tried using a local script but then i realized i can't kick on local scripts. I know little about remote events. Can anyone help?
Player = game:service'Players'.LocalPlayer function click() if script.Parent.Parent.TextBox.Text == "" then else local Reason = script.Parent.Parent.KickReason.Text local Kicked = script.Parent.Parent.TextBox.Text game.Workspace.Players:FindFirstChild(Kicked):Kick("You have been kicked, for Reason: "..Reason ) print(Kicked.." has been kicked by "..Player" For reason: "..Reason) end end script.Parent.MouseButton1Down:connect(click)
I believe a RemoteFunction is what you're looking for. It allows you to execute server scripts within a local script.
Create a server script and put a RemoteFunction inside. Put that script in the script like this. (makes a lot of sense, lol.)
script.RemoteFunction.OnServerInvoke = function(player) Player = game:service'Players'.LocalPlayer script.Parent.MouseButton1Down:connect(function() if script.Parent.Parent.TextBox.Text == "" then else local Reason = script.Parent.Parent.KickReason.Text local Kicked = script.Parent.Parent.TextBox.Text game.Workspace.Players:FindFirstChild(Kicked):Kick("You have been kicked for "..Reason) print(Kicked.." was kicked by "..Player.Name.. " for "..Reason) end end) end
Then, in a local script, do this.
game.Workspace.Script.RemoteFunction:InvokeServer() --Already passes "player", so no need to do so again