Rank and above to change team

Changed a script to this but is not working:

script.Parent.MouseButton1Click:Connect(function()
if game:GetService(“Players”).LocalPlayer:GetRankInGroup(13824371) >= 3 then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Mulberry”)

	wait(0.5)

	script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
end

end)

does it give you any errors? check the output

Sorry for the late reply. I could not get onto my PC.

oh, it’s saying that LocalPlayer doesnt exist because you’re using a script

you should work with a chain of script.Parent. … Parent to get the Player

How would I do that? Would I change local to parent?

you’d get the player similarly to what you did on the line where you set the health to 0 instead off using LocalPlayer

Like this?

script.Parent.MouseButton1Click:Connect(function()
if game:GetService(“Players”).Parent:GetRankInGroup(5122099) >= 3 then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Mulberry”)

	wait(0.5)

	script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
end

end)

no, you need to search through the ancestors of the script to find the player

Oh ok, how would I do that?? I am not sure how.

one way would be to use script.Parent and have a bunch of .Parent
another way is to use script:FindFirstAncestorOfClass(“Player”) to have the script check each parent until it finds the player for you

Like this?

script.Parent.MouseButton1Click:Connect(function()
if game:GetService(“Players”)FindFirstAncestorOfClass(“Player”):GetRankInGroup(5122099) >= 3 then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Mulberry”)

	wait(0.5)

	script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
end

end)

you’d find the first player ancestor of the script, not of game.Players

How would I do that?? Not sure how to.

use script:FindFirstAncestorOfClass("Player"), not game:GetService("Players"):FindFirstAncestorOfClass("Player")

It underlined in red and blue,

script.Parent.MouseButton1Click:Connect(function()
if game:GetService(“Players”).Parent:GetRankInGroup(5122099) >= 3 then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Mulberry”)
script:FindFirstAncestorOfClass(“Player”), not game:GetService(“Players”):FindFirstAncestorOfClass(“Player”)
wait(0.5)

	script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
end

end)

I meant that you need to replace your current code for getting the player with the line of code that uses :FindFirstAncestorOfClass

Hmm, a bit lost tbh, I really don’t much about scripting.

erase:
script:FindFirstAncestorOfClass(“Player”), not game:GetService(“Players”):FindFirstAncestorOfClass(“Player”)

erase:
game:GetService(“Players”).Parent

paste where you just erased:
script:GetFirstAncestorOfClass("Player")

next, erase:
>= 3

and replace that with:
>= 254

I strongly recommend you refer to this:

If you want to lock the team to a certain group rank, in the server script, simply add an if statement to check their group rank.