Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check if a player is on a certain team?

I have this script, and basically, whenever I join, I am the size set in the script. The problem is, I want to know how I can make it work for any player and not just me, and second, I want to make it search for the player's team, and if they're on a certain team, they get sized to that. As of right now, I tried doing game.Teams:FindFirstChild("Name") but that doesn't work for me

Any help is greatly appreciated.

while true do
	wait(.1)
	if game.Players.Name then          -- how do I get this to search for anyone and not me?
		local character = game.Players.Name.Character
		if character then
			local humanoid = character:FindFirstChild("Humanoid")
			if humanoid then
				if humanoid:FindFirstChild("BodyHeightScale") then
					humanoid.BodyHeightScale.Value = 1.12
				end
				if humanoid:FindFirstChild("BodyWidthScale") then
					humanoid.BodyWidthScale.Value = 1.12
				end
				if humanoid:FindFirstChild("BodyDepthScale") then
					humanoid.BodyDepthScale.Value = 1.12
				end
				if humanoid:FindFirstChild("HeadScale") then
					humanoid.BodyDepthScale.Value = 1.12
				end
			end
		end
	end
end

3 comments

0

if player.Team == (team) then it's really easy

0

"how do I get this to search for anyone and not me?" I can help, but first i need to understand do you mean search for all players on the team except your username or except the local player?

0

The local player. For instance, when they join, if they're on that team then they're that size. Right now, it only works for me.

1 answer

✓ Accepted answer

Firstly, make sure this is a Server Script, as making changes on the Client will not replicate to the Server with FilterEnabled set to true

Server Script (Revised)

while true do
	wait(.1)
	for i, v in pairs(game:GetService("Players"):GetPlayers()) do
		local Humanoid = v.Character:WaitForChild("Humanoid")
		if v.Team.Name == "TeamNameHere" and Humanoid.RigType == Enum.HumanoidRigType.R15 then
			Humanoid.BodyHeightScale.Value = 1.12
			Humanoid.BodyWidthScale.Value = 1.12
			Humanoid.BodyDepthScale.Value = 1.12
			Humanoid.HeadScale.Value = 1.12
		end
	end
end

My first method to show you is a revised version of what you attempted.

It should be noted that only R15 can have the "Scale" Values, so you should check that they are in R15 mode instead of using 4 different if-then statements (you can also set the player's character to R15 using the "Game Settings --> Avatar" under the "Home" tab in Studio)

Using the above, we can use the :GetPlayers() function of the Players Service (the Teams service also has this property) which will return a table of the players in the game. We can iterate through the table using a for-loop.

Then we check that their RigType (assuming you allow both R6 and R15) is R15 (which contains the Scale Values) and continue with the script.

Server Script (Suggestion)

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Player:GetPropertyChangedSignal("Team"):Connect(function()
			if Player.Team.Name == "TeamNameHere" and Humanoid.RigType == Enum.HumanoidRigType.R15 then
				Humanoid.BodyHeightScale.Value = 1.12
				Humanoid.BodyWidthScale.Value = 1.12
				Humanoid.BodyDepthScale.Value = 1.12
				Humanoid.HeadScale.Value = 1.12
			end
		end)
	end)
end)

This is the same type of function as before except instead of using a while-loop, you can simply check if the player's team changed to set off the event (which will take up less memory)

To do this, we use the :GetPropertyChangedSignal() function of the player, along with the aforementioned Team / R15 Checks.

This discussion is preserved as it was. New answers, comments, and votes are closed.