(repost) Unable to cast to Dictionary Ban API

this is just a repost but theres a message when i try to ban myself or other people

Screenshot 2024-10-16 025643

and heres the main script

local ps = game:GetService("Players")


function convertDaysToSecends(days)
	return 86400 * tonumber(days)
end


function convertHoursIntoSecends(hours)
	return 3600 * tonumber(hours)
end

local AllowedPeople = {
	1813216757,
	1915724787,
	1029123331,
	2728185622,
}



game.ReplicatedStorage["Banny_Binny!"].OnServerEvent:Connect(function(player, bannedplr, banrsn, bandur)
	if not table.find(AllowedPeople, player.UserId) then return end
	print(tonumber(bandur))
	local plr = ps:FindFirstChild(bannedplr)
	local config: BanConfigType = {
		UserIds = {player:WaitForChild("PlayerGui").Admn.Frame.TextBox.Text}, -- couldnt get this to a pcall statement :()
		tonumber(bandur),
		DisplayReason = banrsn,
		PrivateReason = bannedplr.." Got Banned Because of:"..banrsn
	}

	local success, errorMessage = pcall(function()
		return ps:BanAsync(config)
	end)
	if success then
		print("THE ALMIGHTY BAN CAME")
	else
		warn(errorMessage)
	end
end)

thanks alot if you see this

On the BanAsync function, on UserIds, you are trying to get the userId from you Gui TextBox, but the text is only locally.

Here is the fix:

local ps = game:GetService("Players")

function convertDaysToSecends(days)
	return 86400 * tonumber(days)
end

function convertHoursIntoSecends(hours)
	return 3600 * tonumber(hours)
end

local AllowedPeople = {
	1813216757,
	1915724787,
	1029123331,
	2728185622,
}

game.ReplicatedStorage["Banny_Binny!"].OnServerEvent:Connect(function(player, bannedplr, banrsn, bandur)
	if not table.find(AllowedPeople, player.UserId) then return end
	print(tonumber(bandur))
	local BannedPlayer = ps:FindFirstChild(bannedplr) -- Gets the banned player.
	local config: BanConfigType = {
		UserIds = {BannedPlayer.UserId}, -- Correct UserId
		tonumber(bandur),
		DisplayReason = banrsn,
		PrivateReason = bannedplr.." Got Banned Because of:"..banrsn
	}

	local success, errorMessage = pcall(function()
		return ps:BanAsync(config)
	end)
	if success then
		print("THE ALMIGHTY BAN CAME")
	else
		warn(errorMessage)
	end
end)

it works but the only issue is that it works on studio but not in game

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.