My code appears an error along the lines of " Attempt to index nil with 'Kick' "
Here is my code:
local plname = script.Parent.Text
script.Parent.MouseButton1Click:Connect(function() local plr = game.Players:FindFirstChild(plname) plr:Kick("You have been kicked by a moderator.") end)
If anyone knows the problem please tell me.
I don't really get what you're trying to make..? TextButton isn't customizable unless if it was being controlled by a script. But I'm assuming this is what you're looking for.
Insert a RemoteEvent in ReplicatedStorage, then insert this script (localscript) in the button.
local Players = game:GetService("Players") local RS = game:GetService("ReplicatedStorage") local Event = RS:WaitForChild("KickEvent") -- Change KickEvent to your RemoveEvent name script.Parent.MouseButton1Click:Connect(function() Event:FireServer(script.Parent.Text) end)
Then insert a server script in serverscriptservice
local Players = game:GetService("Players") local RS = game:GetService("ReplicatedStorage") local Event = RS:WaitForChild("KickEvent") -- Again, change it Event.OnServerEvent:Connect(function(plr, target) local plrToKick = Players:FindFirstChild(target) if plrToKick then -- Sanity Check plrToKick:Kick("\n You have been kicked by a moderator") -- \n means new line end end)
Unless if you want to kick yourself then...
Client
script.Parent.MouseButton1Click:Connect(function() game.Players.LocalPlayer:Kick() end)