I haven’t scripted in a year since my pc broke but i decided to continue my game in a small asset game.
This is the Workspace / file thingy
I’m stomped on trying to make a kick command with a console like the dev console.
Local Script contents to register a click and read the text inside a text box
local AdminFolderRS = game.ReplicatedStorage.AdminRemotes
script.Parent.MouseButton1Click:Connect(function()
local command = script.Parent.Parent.TextBox.Text
end)
Here is the stuff for the module script that will handle all commands
local module = {}
function Kick(Player, Reason)
Player:Kick(Reason)
end
return module
Here is the main script that registers when the remote is fired
local AdminFolderRS = game.ReplicatedStorage.AdminRemotes
AdminFolderRS.Send:Connect(function(Player, Reason)
end)
I can’t figure out how to split the text to read a command and player with a reason.
Heres the Gui
In the LocalScript that listens for the button click, you’ll need to split the text from the TextBox into parts (command, player name, and reason) and then send that information via a remote event to the server.
local AdminFolderRS = game.ReplicatedStorage.AdminRemotes
local kickCommand = “kick” – Define the command that will trigger the kick
script.Parent.MouseButton1Click:Connect(function()
– Get the text entered in the TextBox
local commandText = script.Parent.Parent.TextBox.Text
-- Split the text into parts based on spaces
local args = {}
for word in string.gmatch(commandText, "%S+") do
table.insert(args, word)
end
-- Check if the command is "kick"
if args[1] and args[1]:lower() == kickCommand then
-- Ensure there are at least two more parts (player name and reason)
if #args >= 3 then
local playerName = args[2]
local reason = table.concat(args, " ", 3) -- Concatenate all words after the second one as the reason
-- Fire the remote event with the player name and reason
AdminFolderRS.Send:FireServer(playerName, reason)
else
print("Invalid command format. Usage: kick <PlayerName> <Reason>")
end
else
print("Invalid command.")
end
Make sure you’re passing the reason correctly when you call Player:Kick() on the server. In the server script, you should use the reason argument received from the client, not the playerName.
Here’s the updated version of your server-side code with additional clarification:
Updated ServerScript (Handle Remote Event):
Copiar código
local AdminFolderRS = game.ReplicatedStorage.AdminRemotes
local module = require(game.ServerScriptService.KickModule) -- Assuming you have a module for kicking
AdminFolderRS.Send.OnServerEvent:Connect(function(player, playerName, reason)
-- Check if the player sending the request is an admin (optional)
if player:IsInGroup(1234567) then -- Example check for group ID
-- Find the player by name
local targetPlayer = game.Players:FindFirstChild(playerName)
if targetPlayer then
-- Call the Kick function from the KickModule, passing the correct reason
module.Kick(targetPlayer, reason) -- Make sure the 'reason' is passed here
else
print("Player not found: " .. playerName)
end
else
print("You don't have permission to use this command.")
end
end)