local banMessage = script.Parent.Frame.Reason.Text
local DurationText = script.Parent.Frame.Duration.Text
local userName = script.Parent.Frame.PlayerName.Text
local function getBanDuration(durationText)
local duration = tonumber(durationText)
if duration then
return duration
elseif durationText == "permanent" then
return -1
else
return 0
end
end
local function getUserIdFromUsername(username)
local success, userId = pcall(function()
return game.Players:GetUserIdFromNameAsync(username)
end)
if success and userId then
return userId
else
warn("Failed to get UserId for username: " .. username)
return nil
end
end
script.Parent.Frame.ban.Activated:Connect(function()
local userId = getUserIdFromUsername(userName)
if userId then
local banDuration = getBanDuration(DurationText)
if banDuration then
local config = {
UserIds = {userId},
Duration = banDuration,
DisplayReason = banMessage,
PrivateReason = banMessage,
ExcludeAltAccounts = false,
ApplyToUniverse = true
}
local success, err = pcall(function()
return game.Players:BanAsync(config)
end)
if success then
print("User " .. userName .. " successfully banned.")
else
warn("Error banning user " .. userName .. ": " .. err)
end
else
warn("Invalid duration for ban: " .. DurationText)
end
end
end)
script.Parent.Frame.Unban.Activated:Connect(function()
local userId = getUserIdFromUsername(userName)
if userId then
local success, err = pcall(function()
return game.Players:UnbanAsync({
UserIds = {userId},
ApplyToUniverse = true,
})
end)
if success then
print("User " .. userName .. " successfully unbanned.")
else
warn("Error unbanning user " .. userName .. ": " .. err)
end
end
end)
have you tried using Duration = tonumber(DurationText)?
if that isn’t working, try printing the different variables (banMessage, userName etc.) to make sure that they are correctly being passed into :BanAsync.
you can use a local script and RemotEventsRemoteEvent | Documentation - Roblox Creator Hub to handle the GuiButton pressed on the client, just send a signal to the server, verify the user has access to use commands and you’ll be good!