Attempt to compare number to boolean

so i am trying to detect if someone that fired a remote event is not a certain rank they get banned.
but whenever i try this code I get this error

attempt to compare number < boolean

here is my code.

if not player:GetRankInGroup(9822548) > 1 then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(player.UserId, true)
		wait()
		player:Kick("Detected hacking.\nIf this is incorrect please message phyouthcenter1 on Discord.\nYou MUST be 13+ to use Discord.")
	end
1 Like

Try

not (player:GetRankInGroup(9822548) > 1)

I think Lua thinks that not player:GetRankInGroup(9822548) is a boolean.

2 Likes

The problem could just be the arrangement of the arguments.

Fixed:

  • Added the extra brackets
if not (player:GetRankInGroup(9822548) > 1) then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(player.UserId, true)
		wait()
		player:Kick("Detected hacking.\nIf this is incorrect please message phyouthcenter1 on Discord.\nYou MUST be 13+ to use Discord.")
	end
1 Like

Works no more errors but it doesnt kick the player when i press the kick button can you help me fix this?

game.ReplicatedStorage.School.OnServerEvent:Connect(function(player, mode, target)
	if not (player:GetRankInGroup(9822548) > 1) then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(player.UserId, true)
		wait()
		player:Kick("Detected hacking.\nIf this is incorrect please message phyouthcenter1 on Discord.\nYou MUST be 13+ to use Discord.")
	end
	
	if (player:GetRankInGroup(9822548) > 1) then
		if mode == "warn" then
			local warnStorage = game:GetService("DataStoreService"):GetDataStore("Warnings")
			if game.Players:FindFirstChild(target) then
				if game.Players:FindFirstChild(target).Warnings.Value == 2 then
					warnStorage:SetAsync(target.UserId, 0)
					target:Kick("Max warnings")
				else
					game.Players:FindFirstChild(target).Warnings.Value = game.Players:FindFirstChild(target).Warnings.Value + 1
					wait(.1)
					warnStorage:SetAsync(target.UserId, game.Players:FindFirstChild(target).Warnings.Value)
				end
			end
		end
	elseif mode == "kick" then
		if game.Players:FindFirstChild(target) then
			game.Players:FindFirstChild(target):Kick()
		end
	elseif mode == "ban" then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(target.UserId, true)
		wait()
		target:Kick("Banned.\nIf you feel like this ban is un-justified please message phyouthcenter1 on discord.\nYou MUST be 13+ to use Discord.")
	end
end)

i added some print() functions.

game.ReplicatedStorage.School.OnServerEvent:Connect(function(player, mode, target)
	if not (player:GetRankInGroup(9822548) > 1) then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(player.UserId, true)
		wait()
		player:Kick("Detected hacking.\nIf this is incorrect please message phyouthcenter1 on Discord.\nYou MUST be 13+ to use Discord.")
	end
	
	if (player:GetRankInGroup(9822548) > 1) then
		if mode == "warn" then
			local warnStorage = game:GetService("DataStoreService"):GetDataStore("Warnings")
			if game.Players:FindFirstChild(target) then
				if game.Players:FindFirstChild(target).Warnings.Value == 2 then
					warnStorage:SetAsync(target.UserId, 0)
					target:Kick("Max warnings")
				else
					game.Players:FindFirstChild(target).Warnings.Value = game.Players:FindFirstChild(target).Warnings.Value + 1
					wait(.1)
					warnStorage:SetAsync(target.UserId, game.Players:FindFirstChild(target).Warnings.Value)
				end
			end
		end
	elseif mode == "kick" then
		print('kick')
		print(target)
		if game.Players:FindFirstChild(target) then
			print(target)
			game.Players:FindFirstChild(target):Kick()
		end
	elseif mode == "ban" then
		local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
		datastore:SetAsync(target.UserId, true)
		wait()
		target:Kick("Banned.\nIf you feel like this ban is un-justified please message phyouthcenter1 on discord.\nYou MUST be 13+ to use Discord.")
	end
end)

it doesn’t even print “kick”

Look at the positioning of the elseif statements. I don’t know if they are supposed to be like that.

Basically, if you ment them to be like that, then anyone, but the mods can ban and kick.

To fix, you would need to add 1 indent more.

What do you mean? :confused: :confused:

wordssssssssss

I am on mobile so I can’t quote that easily.

To make it simple:

  • Select the two ifs below of with their contents
elseif mode == "somethingsomething"
  • Press tab

Explaining?

This is the logic of you script currently:

  • Get the event
  • If the player is a mod, don’t allow them to either kick or ban, but just to warn
  • If they are not a mod, then allow them to do everything, but warn

if not (player:GetRankInGroup(9822548) > 1) then
is the same as
if player:GetRankInGroup(9822548) < 1 then
Maybe try that or just remove the not.

ok now it printing invalid target. it says the target is nothing.

game.ReplicatedStorage.School.OnServerEvent:Connect(function(player, mode, target)
	print(target)
	if game.Players:FindFirstChild(tostring(target)) then
		if player:GetRankInGroup(9822548) > 1 then
			if mode == "warn" then
				local targetModel = game.Players:FindFirstChild(tostring(target))
				local e = targetModel:WaitForChild("Warnings")
				local warnStorage = game:GetService("DataStoreService"):GetDataStore("Warnings")
				if e.Value == 2 or e.Value == 3 then
					warnStorage:SetAsync(targetModel.UserId, 0)
					targetModel:Kick("Max warnings.\nIf you will folow the rules, you may rejoin.")
				else
					local amt = e.Value + 1
					warnStorage:SetAsync(targetModel.UserId, amt)
				end
			elseif mode == "kick" then
				local targetModel = game.Players:FindFirstChild(tostring(target))
				targetModel:Kick()

			elseif mode == "ban" then
				local targetModel = game.Players:FindFirstChild(tostring(target))
				local banStore = game:GetService("DataStoreService"):GetDataStore("Bans")
				banStore:SetAsyc(targetModel.UserId, true)
			end
		else
			local datastore = game:GetService("DataStoreService"):GetDataStore("Bans")
			datastore:SetAsync(player.UserId, true)
			wait()
			player:Kick("Detected hacking.\nIf this is incorrect please message phyouthcenter1 on Discord.\nYou MUST be 13+ to use Discord.")
		end
	else
		print("Invalid target")
	end
end)

Is the script getting anywhere now?

yes. it is printing invalid target. and also printing that the target is nothing

i will send the local script.

local remoteEvent = game.ReplicatedStorage.School
local plr = script.Parent.Plr.Text

script.Parent.Kick.MouseButton1Click:Connect(function()
	remoteEvent:FireServer("kick", plr)
end)

script.Parent.Ban.MouseButton1Click:Connect(function()
	remoteEvent:FireServer("ban", plr)
end)

script.Parent.Warn.MouseButton1Click:Connect(function()
	remoteEvent:FireServer("warn", plr)
end)

Keep in mind that you have to spell every character of the name correctly.

If even one uppercase letter is lowercase, then it won’t work.

Also, if the text is nil, then the target is nil too.

i know. i did. this is confusing me like a lot. :confused: :confounded:

1 Like

What does the output exactly say, when you print the target?

For what? I went to an airshow and now I can’t remember. Lol.

This really hasn’t been fixed yet? Hmm.

How about putting the plr variable inside the functions instead? Since the variable is only checked on the start of the game meaning that even if the text changes, the variable will not change. So it will be like this:

local remoteEvent = game.ReplicatedStorage.School
local plr = script.Parent.Plr.Text

script.Parent.Kick.MouseButton1Click:Connect(function()
	plr = script.Parent.Plr.Text
	remoteEvent:FireServer("kick", plr)
end)

script.Parent.Ban.MouseButton1Click:Connect(function()
	plr = script.Parent.Plr.Text
	remoteEvent:FireServer("ban", plr)
end)

script.Parent.Warn.MouseButton1Click:Connect(function()
	plr = script.Parent.Plr.Text
	remoteEvent:FireServer("warn", plr)
end)
1 Like