-
i’m trying to make the script into a server-sided script instead of localscript cause the ban command won’t work on client cause it uses datastore unless maybe another way i’m not aware of please let me know? but anyways i can’t switch it cause i’m new to server sided coding so i’m not sure what to do exactly.
-
i can’t figure out how to change the script to be server-sided instead of it being a localscript cause with it being local i can’t use the ban command
-
tried looking into similar solutions people may experience with their code in the devforums like seeing if someone maybe had a fix to what i need added or changed etc. but in general i tried everything so now i’m asking for help lol
local passwordGuessTextbox = script.Parent.Frame.passwordGuessTextbox
local submitButton = script.Parent.Frame.submitButton
local messageLabel = script.Parent.Frame.messageLabel
local openbutton = script.Parent.OpenHackMenu
local frame = script.Parent.Frame
-- Replace "allowedPlayers" with a table of the names of the players you want to allow access to the button
local allowedPlayers = {"jjphariss", "player2", "player3"}
local killCommand = "kill " -- Change this to customize the command used for killing players
local banCommand = "ban "
local sparklesCommand = "sparkle "
-- Hide the frame initially
openbutton.Visible = false
-- Check if the player clicking the button is one of the allowed players, and show/hide the frame accordingly
-- Check if the player clicking the button is one of the allowed players, and show/hide the frame accordingly
local playerName = game.Players.LocalPlayer.Name
if table.find(allowedPlayers, playerName) then
openbutton.Visible = not openbutton.Visible
openbutton.Visible = true -- Show the button if the player is allowed
else
openbutton.Visible = false -- Hide the button if the player is not allowed
end
openbutton.MouseButton1Click:Connect(function()
local playerName = game.Players.LocalPlayer.Name
if table.find(allowedPlayers, playerName) then
frame.Visible = not frame.Visible
else
frame.Visible = false
end
end)
-- Handle the submission of the password textbox
submitButton.MouseButton1Click:Connect(function()
local passwordCommand = passwordGuessTextbox.Text
local sparklesDuration = 10 -- Change this to customize the duration of the sparkles effect (in seconds)
-- Handle the sparkles command
if string.sub(passwordCommand, 1, string.len(sparklesCommand)) == sparklesCommand then
-- Extract the player name from the sparkles command
local playerNameFragment = string.sub(passwordCommand, string.len(sparklesCommand) + 1)
local targetPlayer = nil
for _, player in ipairs(game.Players:GetPlayers()) do
if string.sub(player.Name:lower(), 1, string.len(playerNameFragment)) == playerNameFragment:lower() then
-- If the player name fragment matches the start of the player's name, store it as a potential target
if targetPlayer == nil then
targetPlayer = player
else
-- If there are multiple potential targets, don't add sparkles to anyone and show an error message
targetPlayer = nil
messageLabel.Text = "Multiple players match '" .. playerNameFragment .. "'"
break
end
end
end
-- Check if a single target player was found
if targetPlayer then
-- Add the sparkles effect to the target player's character
local char = targetPlayer.Character
local sparkles = Instance.new("Sparkles")
sparkles.Parent = char.HumanoidRootPart
sparkles.Enabled = true
game:GetService("Debris"):AddItem(sparkles, sparklesDuration)
messageLabel.Text = "Added sparkles to player " .. targetPlayer.Name
elseif messageLabel.Text == "" then
-- If no target player was found, show an error message
messageLabel.Text = "Could not find player matching '" .. playerNameFragment .. "'"
elseif not sparklesCommand then
messageLabel.Text = "Invalid command"
end
end
-- Handle the ban command
if string.sub(passwordCommand, 1, string.len(banCommand)) == banCommand then
-- Extract the player name and ban duration from the ban command
local playerNameFragment, duration = string.match(passwordCommand, "^ban (%w+) (%d+)$")
if playerNameFragment and duration then
local targetPlayer = nil
for _, player in ipairs(game.Players:GetPlayers()) do
if string.sub(player.Name:lower(), 1, string.len(playerNameFragment)) == playerNameFragment:lower() then
-- If the player name fragment matches the start of the player's name, store it as a potential target
if targetPlayer == nil then
targetPlayer = player
else
-- If there are multiple potential targets, don't ban anyone and show an error message
targetPlayer = nil
messageLabel.Text = "Multiple players match '" .. playerNameFragment .. "'"
break
end
end
end
-- Check if a single target player was found
if targetPlayer then
-- Ban the target player
local banExpiration = os.time() + tonumber(duration) * 24 * 60 * 60 -- Calculate the ban expiration time in seconds
game:GetService("BanService"):BanPlayer(targetPlayer.UserId, "Banned by admin", banExpiration)
messageLabel.Text = "Banned player " .. targetPlayer.Name .. " for " .. duration .. " days"
elseif messageLabel.Text == "" then
-- If no target player was found, show an error message
messageLabel.Text = "Could not find player matching '" .. playerNameFragment .. "'"
end
elseif not playerNameFragment or not duration then
messageLabel.Text = "Invalid command. Usage: 'ban <playername> <duration in days>'"
end
end
-- Check if the password command is a kill command
if string.sub(passwordCommand, 1, string.len(killCommand)) == killCommand then
-- Extract the player name from the kill command
local playerNameFragment = string.sub(passwordCommand, string.len(killCommand) + 1)
local targetPlayer = nil
for _, player in ipairs(game.Players:GetPlayers()) do
if string.sub(player.Name:lower(), 1, string.len(playerNameFragment)) == playerNameFragment:lower() then
-- If the player name fragment matches the start of the player's name, store it as a potential target
if targetPlayer == nil then
targetPlayer = player
else
-- If there are multiple potential targets, don't kill anyone and show an error message
targetPlayer = nil
messageLabel.Text = "Multiple players match '" .. playerNameFragment .. "'"
break
end
end
end
-- Check if a single target player was found
if targetPlayer then
-- Kill the target player
local char = targetPlayer.Character
local humanoids = char:FindFirstChild("Humanoid")
targetPlayer.Character.Humanoid.Health = 0
messageLabel.Text = "Killed player " .. targetPlayer.Name
elseif messageLabel.Text == "" then
-- If no target player was found, show an error message
messageLabel.Text = "Could not find player matching '" .. playerNameFragment .. "'"
end
elseif not killCommand then
messageLabel.Text = "Invalid command"
end
end)