Help making a ban button

Hi im making a ban button following a tutorial like i always do and ive ran into a problem ive completed the script but it wont work and i dont know why heres the scripts:

Server script:

		local versionNumber = 1
		local banstorage = game.DataStoreService:GetService("Ban storage v"..versionNumber)
		local admins = {
			
			["1kLxfe"] = 1;
			["spydercam500"] = 1;
			["masry12"] = 1;
			["Crazyloco04"] = 1;
			["xShadowExiled"] = 1;
			
		}

		game.Players.PlayerAdded:Connect(function(player)
			local previousData = banstorage:GetAsync(player.UserId)
			
			if previousData == nil then
				-- they dont have any data
				
				banstorage:SetAsync(player.UserId, false)
				--false equal to not banned true equaled to banned
			else
				if previousData == true then
					--they are banned
					player:Kick("You are banned LOOOL!")
				else
					print("Player is not banned!")
				end
			end
		end)

		game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim)
			if admins[player.Name] then
				
				-- if they are a admin
				
				local found = game.Players:FindFirstChild(victim)
				
				if found then
					banstorage:SetAsync(found.UserId, true)
					found:Kick("You are banned LOOOL!")
				end
			end
		end)

Local script:

		local button  =  script.Parent

		local textbox = script.Parent.Parent.Parent.PlayerNameBox


		button.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.Ban:FireServer(textbox.Text)
		end)
1 Like

And there are no errors incase your wondering

You’re attempting to combine “Ban storage v”, which is a string, with an integer in the server script. (I haven’t read through the entire script btw so I might have overlooked something).

You can just fix it by changing line 1 to

local versionNumber = "1"
1 Like

Still doesnt work for some reason ive even tried to remove myself from the admins list.

Could you try adding print statements to see where the code stops functioning?

I think ive maybe found the problem and its in the local script ok so i put a print to see what line it stopped at after the admin varible in the server script and it didnt work when i pressed the “ban” button
Yes1
That means there must be a error in the local script

I don’t think so, since the print statement isn’t in the OnServerEvent so it’s something wrong with the server script.

1 Like

Ok well i found out that the local script was in the wrong button but it still doesnt work for some reason ive fixed the varible for the PlayerNameBox to and still doesnt work

	local banstorage = game.DataStoreService:GetService("Ban storage v"..versionNumber)

Umm, So you’re doing something weird???

You need to use
local DataStoreService = game:GetService("DataStoreService") and
local DataStore = DataStoreService:GetDataStore("BanServer")

I don’t know why they put game.DataStoreService:GetService, but that just doesn’t work. (Scripting wise)

And are there any errors in the output bar?

1 Like

No errors also i followed a tutorial to make this and i havent learned about DataStores yet
Also do i remove the

Try changing line 2 to

local banstorage = game:GetService("DataStoreService"):GetDataStore("Ban storage v"..versionNumber)
1 Like

It worked! Thanks! Now i can implement this into my game Thanks again!
(This was before i noticed it wasnt banning the person when they joined back)

Ok so this did solve the problem with the ban button itself but ive ran into another issue when the player rejoins there not banned after being banned so its more of a kick button then a ban button why is this?

if banstorage:GetAsync(player.UserId) then
	-- kick player
end

Give this one a shot, replace the quoted part with this and lmk if it works, I’m on mobile and haven’t gotten the chance to test it yet. Also are there any errors?

1 Like

There are no errors also sorry for late response

It kicks but doesnt ban forever still

local versionNumber = "1"
local banstorage = game:GetService("DataStoreService"):GetDataStore("Ban storage v"..versionNumber)
local admins = {

	["1kLxfe"] = 1;
	["spydercam500"] = 1;
	["masry12"] = 1;
	["Crazyloco04"] = 1;
	["xShadowExiled"] = 1;

}

game.Players.PlayerAdded:Connect(function(player)
	if banstorage:GetAsync(player.UserId) then
		player:Kick("You are banned LOOOL!")
	end
end)

game.ReplicatedStorage.Ban.OnServerEvent:Connect(function(player, victim)
	if admins[player.Name] then

		-- if they are a admin

		local found = game.Players:FindFirstChild(victim)

		if found then
			banstorage:SetAsync(found.UserId, true)
			found:Kick("You are banned LOOOL!")
		end
	end
end)

Here’s what I have now, this works for me.
Let me know how it goes

edit: (i noticed i accidentally quoted something)

1 Like

It doesnt work still its kicking me from the game but not kicking me when i rejoin do you need my workspace?

Strange, I’ve just tried it and it seems to work fine, could you make sure you have API turned on?

1 Like

I do have api turned on