What I'm trying to do is kick players by typing in their name and clicking to kick. But the error that keep popping up is "Cannot kick a non-local Player from a LocalScript", which means, it only allows me to kick myself but not others... Any help?
--Made by IIApexGamerII, all credits go to Creator. local VanGui = Instance.new("ScreenGui") local Van = Instance.new("Frame") local idk = Instance.new("TextBox") local dsa = Instance.new("TextButton") VanGui.Name = "Kick" VanGui.Parent = game.Players.LocalPlayer.PlayerGui Van.Name = "Kick" Van.Parent = VanGui Van.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) Van.BorderColor3 = Color3.new(0, 0, 0) Van.Position = UDim2.new(0, 5, 0.8, 0) Van.Size = UDim2.new(0, 200, 0, 45) idk.Name = "idk" idk.Parent = Van idk.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) idk.BorderColor3 = Color3.new(0, 0, 0) idk.Size = UDim2.new(1, 0, 0, 20) idk.Font = Enum.Font.SciFi idk.FontSize = Enum.FontSize.Size14 idk.Text = "Username" idk.TextColor3 = Color3.new(1, 1, 1) idk.TextScaled = true idk.TextStrokeTransparency = 0 idk.TextWrapped = true dsa.Name = "dsa" dsa.Parent = Van dsa.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) dsa.BorderColor3 = Color3.new(0, 0, 0) dsa.Position = UDim2.new(0, 0, 1, -25) dsa.Size = UDim2.new(1, 0, 0, 25) dsa.Font = Enum.Font.SciFi dsa.FontSize = Enum.FontSize.Size14 dsa.Text = "Kick a Player" dsa.TextColor3 = Color3.new(1, 1, 1) dsa.TextScaled = true dsa.TextStrokeTransparency = 0 dsa.TextWrapped = true dsa.MouseButton1Click:connect(function() wait(0.2) game.Players[idk.Text]:Kick("You were kicked by "..game.Players.LocalPlayer.Name..".") end)
I would gladly appreciate it.
The reason this is happening is to prevent exploiters, so that people don't kick other players.
For this you would use a RemoteEvent
The server will handle it and kick the player. Put a remote event in the replicated storage named KickPlayer
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage") ReplicatedStorage:WaitForChild("KickPlayer") ReplicatedStorage.KickPlayer:FireServer(idk.Text)
Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") ReplicatedStorage:WaitForChild("KickPlayer") ReplicatedStorage.KickPlayer.OnServerEvent:Connect(function(player,name) local plr = game.Players:FindFirstChild(name) if plr and plr:IsA("Player") then plr:Kick("You were kicked by "..player.Name..".") end end)
But whatever you do, BE CAREFUL. A malicious player can fire the remote event and use it to kick other players, so whatever you're doing, don't give the client too much power, and make sure that the player who fired the event is allowed to do that.
--Made by IIApexGamerII, all credits go to Creator. local VanGui = Instance.new("ScreenGui") local Van = Instance.new("Frame") local idk = Instance.new("TextBox") local dsa = Instance.new("TextButton")
VanGui.Name = "Kick" VanGui.Parent = game.Players.LocalPlayer.PlayerGui
Van.Name = "Kick" Van.Parent = VanGui Van.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) Van.BorderColor3 = Color3.new(0, 0, 0) Van.Position = UDim2.new(0, 5, 0.8, 0) Van.Size = UDim2.new(0, 200, 0, 45)
idk.Name = "idk" idk.Parent = Van idk.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) idk.BorderColor3 = Color3.new(0, 0, 0) idk.Size = UDim2.new(1, 0, 0, 20) idk.Font = Enum.Font.SciFi idk.FontSize = Enum.FontSize.Size14 idk.Text = "Username" idk.TextColor3 = Color3.new(1, 1, 1) idk.TextScaled = true idk.TextStrokeTransparency = 0 idk.TextWrapped = true
dsa.Name = "dsa" dsa.Parent = Van dsa.BackgroundColor3 = Color3.new(0.235294, 0.235294, 0.235294) dsa.BorderColor3 = Color3.new(0, 0, 0) dsa.Position = UDim2.new(0, 0, 1, -25) dsa.Size = UDim2.new(1, 0, 0, 25) dsa.Font = Enum.Font.SciFi dsa.FontSize = Enum.FontSize.Size14 dsa.Text = "Kick a Player" dsa.TextColor3 = Color3.new(1, 1, 1) dsa.TextScaled = true dsa.TextStrokeTransparency = 0 dsa.TextWrapped = true
dsa.MouseButton1Click:connect(function() wait(0.2) game.Players[idk.Text]:Kick("You were kicked by "..VanGui.Parent.Parent.Name..".") end)