Why does :GetrankInGroup is not working

I made an admin panel script which does The Following:
1-when the player press The Trriger Button
2- it fires a remote_event in RP_Storage With some paramters (Like Textbox Text)
3- and there is a server_script that Detects when The remote_Event is fired and does The following:

The Local Script:

script.Parent.MouseButton1Click:Connect(function()
	local TextR = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox").Text
	local TextMs = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox2").Text
	local TextK = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox3").Text
	local TextH = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox4").Text
	local TextS = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox5").Text
	local Button2 = game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox").Text
	game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer(TextR,TextMs,TextK,TextH,TextS)
	if game.Players.LocalPlayer:GetRankInGroup(1234) ~= 255 then
		print("This Gui owner does not Have The Acciplity To Use Secret Commands")
	elseif game.Players.LocalPlayer:GetRankInGroup(1234) == 255 or game.Players.LocalPlayer:GetRankInGroup(1234) == 2	 then
		print("initiating The Secret Commands")
		game.Players.LocalPlayer.PlayerGui.ScreenGui_S:WaitForChild("Frame"):WaitForChild("TextBox5").Visible = true
	end
end)

The Server_Script:

game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player ,TextR, TextMs, TextK, TextH, TextS)
	for _,Item in pairs(game.Players:GetChildren()) do
		if Item.Name == TextR and Item:GetRankInGroup(1234) ~= 255 then
			Item:Kick(TextMs)
			print("Player: "..Item.Name.." Got Kicked")
		elseif Item.Name == TextR and Item:GetRankInGroup(1234) == 255 then
			print("kicking The owner?")
		end
	end --end For player loop	
	
	
	for _, Item in pairs(game.Workspace:GetChildren()) do
		if Item.Name == TextK then
			local hum = Item:FindFirstChild("Humanoid")
			local Char = hum.Parent
			local Achivet_Player = game:GetService("Players"):GetPlayerFromCharacter(Char)
			if hum and Achivet_Player:GetRankInGroup(1234) ~= 255 and Achivet_Player  then
				hum.Health = 0
				print(Achivet_Player.Name)
			elseif hum and Achivet_Player:GetRankInGroup(1234) == 255 and Achivet_Player then
				print("You Cant Kill The owner")
			end
		end -- end of the Kill Loop
		

and here is the error:
Annotation 2022-11-18 153713

and For Some Reason i tryed it with The same exact Script But in Diffrent Place
and it somehow worked

You are not using the player Variable on the RemoteEvent

Plus, you can only Get the Group Rank from the player, not the character

So this line is your issue

--[[ Error Line
local Achivet_Player = game:GetService("Players"):GetPlayerFromCharacter(Char)
--]]
			if hum and Achivet_Player:GetRankInGroup(1234) ~= 255 and Achivet_Player  then
				hum.Health = 0
				print(Achivet_Player.Name)
			elseif hum and Achivet_Player:GetRankInGroup(1234) == 255 and Achivet_Player then
				print("You Cant Kill The owner")
			end
1 Like

so i just have to remove this line and replace it with the player parameter in the remote event?

Yes, the first parameter is the Player always with the exception of the Client

But just do this:

if hum and player:GetRankInGroup(1234) ~= 255 and Achivet_Player  then
				hum.Health = 0
				print(Achivet_Player.Name)
			elseif hum and player:GetRankInGroup(1234) == 255 and player then
				print("You Cant Kill The owner")
			end

ill say this once again, you cannot get the Players Rank through the character
Edit: lol i misread

the reason i used the Achivet_Player variable is cuz i want to get the Rank of the player that is targeted
not the player that is firing the remote

and thats cuz i dont want the That Command to exute for a player that have a certain rank
you know what i mean?

Also looking at your code, cant you use use Item?

for _, Item in pairs(game.Workspace:GetChildren()) do
		if Item.Name == TextK then
			local hum = Item:FindFirstChild("Humanoid")
			local Achivet_Player = game:GetService("Players"):GetPlayerFromCharacter(Item)

(Nope, LOL, Maybe idk)

i dont think it will matter in the script

pro i didnt Get the Rank From The Character
i first got the player From The character
and then used that player variable to get the rank

i will try finding another way to fix it
but for now
thank you @DasKairo for your Time