My script is not working

My script is not working, it is supposed to check if a player joins and if they are in the group and a certain rank it should change the texture id of there shirt

local clothId = 6224708148

function onPlayerEntered(plyr)
	if plyr:GetRankInGroup(7958564) == 253 then
		local char = game.Players.LocalPlayer
		local shirt = char:FindFirstChildOfClass("Shirt")

		shirt.ShirtTemplate = clothId
	end
end

1 - Is this in a Local Script or a Server Script?
2 - The player character isn’t declarated correctly.
3 - Did you add a event that connects to the function when a player joins the game?

Here is what you could do (make sure to put this in a server script):

local clothId = 6224708148

function onPlayerEntered(plyr)
	if plyr:GetRankInGroup(7958564) == 253 then
		local char = plyr.Character or plyr.CharacterAdded:Wait()
		local shirt = char:FindFirstChildOfClass("Shirt")

		shirt.ShirtTemplate = clothId
	end
end

game.Players.PlayerAdded:Connect(onPlayerEntered)
1 Like

you forgot to call the function, you also defined the player instead of the character:

local clothId = 6224708148

function onPlayerEntered(plyr)
	if plyr:GetRankInGroup(7958564) == 253 then
		local char = game.Players.LocalPlayer.Character
		local shirt = char:FindFirstChildOfClass("Shirt")

		shirt.ShirtTemplate = clothId
	end
end
game.Players.PlayerAdded:Connect(onPlayerEntered)
local clothId = 6224708148

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if plr:GetRankInGroup(7958564) == 253 then
			local shirt = char:FindFirstChildOfClass("Shirt")
			if shirt then
				shirt.ShirtTemplate = "rbxassetid://"..clothId
			end
		end
	end)
end)