Why won't this script work?

So I have no errors, I may be doing this script wrong but here. If someone could fix my script r something.

my script is

game.Players.PlayerAdded:Connect(function(Player)
	script.Parent.MouseButton1Click:Connect(function()	
		if Player:GetRankInGroup(5593343) == 254 then
			print("Player is corect rank!")
			Player.TeamColor = BrickColor.new("Really red")
		else print("Player is not correct rank")	
			Player.TeamColor = BrickColor.new("Dark stone grey")
		end

	end)
end)

It’s supposed to give the people who are that rank the “Red” rank, but if you aren’t the correct rank then you stay on Choosing team. Here is screen shot of explorer

image

There are a few issues here. First of all, you’re trying to run a ServerScript from the client. Instead, you will need to use a LocalScript to detect when the button is pressed. Secondly, you can not set a team of a player from the client since it won’t replicate to the server. Instead, you will need to use a RemoteEvent.

So for the LocalScript you should do something like this:

local RemoteEvent = game:GetService("ReplicatedStorage").Event -- A path to your RemoteEvent

script.Parent.MouseButton1Click:Connect(function()	
    RemoteEvent:FireServer()
end)

And in the ServerScript you would put the rest of your code:

local RemoteEvent = game:GetService("ReplicatedStorage").Event -- A path to your RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(Player)
	if Player:GetRankInGroup(5593343) == 254 then
		print("Player is corect rank!")
		Player.TeamColor = BrickColor.new("Really red")
	else
		print("Player is not correct rank")	
		Player.TeamColor = BrickColor.new("Dark stone grey")
	end
end)

That should hopefully solve your problem.

where would I put the server script and local script?

The LocalScript should be at the same place as your current ServerScript (Under the button) and the ServerScript somewhere in ServerScriptService

Okay let me test it brb. Thank you if it works.