[SOLVED] The admin gets warned even though, the kick system is working [PATCHED]

Hello guys once again, i found another issue but this time it’s a BIG issue…

Script:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer
-- You can ignore these 3 but i recommend to keep it to make it as a shorten way on the lines.
script.Parent.MouseButton1Click:Connect(function()
	if username.Text == game.Players then
		print("You kicked "..username.Text)
		if game.Players:FindFirstChild(username.Text) then
			game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
			game.Players.LocalPlayer:Kick(reason.Text)
		end
	else
		if username.Text ~= game.Players then
			warn("You tried to kick "..username.Text.." but it's an invalid username !")
		end
		if reason.Text == "" then
			game.Players.LocalPlayer:Kick("Unknow reason")
		else
			game.Players.LocalPlayer:Kick(reason.Text)
		end
	end
end)

Warning, it’s a LocalScript, it’s in the KickButton and the AdminPanel Gui it’s on the Handler Script which is in the ServerScriptService.

Video:

Instead of “be” it’s “me”.

Image of the warn no prints:

If it’s marked as a blue thing, it means you don’t count it.

So yeah guys, any help is appreciated.

I just realized that it could be really hard, the bug.

1 Like

I believe the text saying “Cannot write to DataStore from studio if API access is not enabled.” means that it cannot write to a datastore from studio if api access if not enabled. I could be wrong though.

Also, it’s giving the warning because you’re trying to see if a string is not an instance. Obviously all strings aren’t instances, so it’s going to give you that warning.

I just said do not read the blue thing.

I just want to do a localscript but if the username is wrong, it warns the admin…

By the way, there’s no prints…

If text is an instance (which will never happen) then do the code

I’ve made the script diffirently:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if game.Players:FindFirstChild(username.Text) then
		game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
		game.Players.LocalPlayer:Kick(reason.Text)
		
		if reason.Text == "" then
			game.Players.LocalPlayer:Kick("Unknow reason.")
		else
			game.Players.LocalPlayer:Kick(reason.Text)
		end
		
		print("You kicked "..username.Text)
		
		if username.Text == "" then
			warn("You tried to kick an unknow person but it's an invalid username !")
		end
	end
end)

And it did not worked.
I guess…

Try replacing:

if username.Text == game.Players then

With This:

if table.find(game:GetService("Players"), username.Text) then

Also, I would like to know what is script.Parent.Parent.Username.
Is it a string value or some GUI?

I changed the script again and it works now.

I keep getting better and better in scripting, man.

Script:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if username.Text == "" then
		warn("You tried to kick an unknow person but it's an invalid username !")
	else
		warn("You tried to kick "..username.Text.." but it's an invalid username !") 

		if game.Players:FindFirstChild(username.Text) then
			print("You kicked "..username.Text)
			game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
			game.Players.LocalPlayer:Kick(reason.Text)

			if reason.Text == "" then
				game.Players.LocalPlayer:Kick("Unknow reason.")
			else
				game.Players.LocalPlayer:Kick(reason.Text)

			end
		end
	end
end)

Videos (Still warns me even though the username is correct at the 1st video):

1:

2:

3:

It’s actually the TextBox.

Char limit.

Try this:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    if game.Players:FindFirstChild(username.Text) then
		warn("The username is valid and the player will be kicked shortly")
	else
		warn("You tried to kick "..username.Text.." but it's an invalid username !") 

		if game.Players:FindFirstChild(username.Text) then
			print("You kicked "..username.Text)
			game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
			game.Players.LocalPlayer:Kick(reason.Text)

			if reason.Text == "" then
				game.Players.LocalPlayer:Kick("Unknow reason.")
			else
				game.Players.LocalPlayer:Kick(reason.Text)

			end
		end
	end
end)

The problem was in this part:

if username.Text == "" then
		warn("You tried to kick an unknow person but it's an invalid username !")
	else
		warn("You tried to kick "..username.Text.." but it's an invalid username !") 

Here, if the username was nothing then it would warn that it was unknown and if it was anything else either it is invalid or a valid username, it would execute the else statement.
If this solved the problem don’t forget to mark the topic as solved.

Huh, why do you mean ?

My script works, not yours, sorry because it has a blank on the line 9.

So i like to prefer to do:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if username.Text == "" then
		warn("You tried to kick an unknow person but it's an invalid username !")
	else
		warn("You tried to kick "..username.Text.." but it's an invalid username !") 

		if game.Players:FindFirstChild(username.Text) then
			print("You kicked "..username.Text)
			game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
			game.Players.LocalPlayer:Kick(reason.Text)

			if reason.Text == "" then
				game.Players.LocalPlayer:Kick("Unknow reason.")
			else
				game.Players.LocalPlayer:Kick(reason.Text)

			end
		end
	end
end)

Instead of:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    if not game.Players:FindFirstChild(username.Text) then
        warn("You tried to kick "..username.Text.." but it's an invalid username !") 
	else
		warn("The username is valid and the player will be kicked shortly")

		if game.Players:FindFirstChild(username.Text) then
			print("You kicked "..username.Text)
			game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
			game.Players.LocalPlayer:Kick(reason.Text)

			if reason.Text == "" then
				game.Players.LocalPlayer:Kick("Unknow reason.")
			else
				game.Players.LocalPlayer:Kick(reason.Text)

			end
		end
	end
end)

My bad there was a small mistake. It should work now

It’s the same thing, but you switched the:

And:

Okay this is a trainwreck, first things first:

Here’s all you need for the Client side of it (LocalScript)

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if not game.Players:FindFirstChild(username.Text) then
		warn("You tried to kick "..username.Text.." but it's an invalid username !") 
		return
	end
	if game.Players:FindFirstChild(username.Text) then
		print("You kicked "..username.Text)
		game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
		-- Removed the LocalPlayer kick, what were you even trying to accomplish there?
	end
end)

Now, if you would, please send your ServerScript that handles the “KickPlayer” RemoteEvent in ReplicatedStorage, if you don’t have one, I’ll make you one.

There’s a blank beteewn the “kick” and “but”.

So no, sorry.

I actually did not put a username in it…

Okay what are you talking about?

I need to know EXACTLY what you want to do.
You’re not giving me anymore info, you’re just outright denying the offer of assistance.
I don’t mean to be rude, but if you’re going to ask for help, you’ll have to put the effort in to give those who care to help info, and more importantly, a chance to help.

I forgot that i putted @elomala’s script…

And plus, it did not kicked me…

Try this version, it should fix the small detail you had concerned.

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if username.Text:gsub("%s", "") == "" then -- :gsub("%s", "") just ensures we do not count " " as a username
		warn("You must supply a username before kicking.")
		return
	end
	if not game.Players:FindFirstChild(username.Text) then
		warn("There is no Player named \""..username.Text.."\" in the server!") 
		return
	end
	if game.Players:FindFirstChild(username.Text) then
		print("You kicked "..username.Text)
		game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
		-- Removed the LocalPlayer kick, what were you even trying to accomplish there?
	end
end)

We will get down to the “Kicking” part of the script later, you should never kick on the Client, you need a server script, which as I said, we will get to soon.

Did not kicked…

Char limit

Added myself some lines:

local username  = script.Parent.Parent.Username
local reason = script.Parent.Parent.Reason
local Player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if username.Text:gsub("%s", "") == "" then -- :gsub("%s", "") just ensures we do not count " " as a username
		warn("You must supply a username before kicking.")
		return
	end
	if not game.Players:FindFirstChild(username.Text) then
		warn("There is no Player named \""..username.Text.."\" in the server!") 
		return
	end
	if game.Players:FindFirstChild(username.Text) then
		print("You kicked "..username.Text)
		game.ReplicatedStorage.KickPlayer:FireServer(username.Text, reason.Text)
		game.Players.LocalPlayer:Kick(reason.Text)
		if reason.Text == "" then
			game.Players.LocalPlayer:Kick("Unknow reason given.")
		else
			game.Players.LocalPlayer:Kick(reason.Text)
		end
	end
end)

Thanks to @IDoLua to help me.
@elomala, Thanks to try to help me.
@cpguy5089, Thanks to try to help me.