New issue with outfit changers

Hey there, in a previous post I had an issue with my outfit changer and it worked fine. However, now it doesn’t put the uniform on when a player steps on the part.

script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local Character = Player:WaitForChild("Character")

	if Player:GetRankInGroup(4789894) <= 8 then
		local Shirt = Character.Shirt
		local Pants = Character.Pants

		if not Shirt then
			Shirt = Instance.new("Shirt", Character)
		end

		if not Pants then
			Pants = Instance.new("Pants", Character)
		end	

		Pants.PantsTemplate = script.Parent.Uniform.LR.Pants.PantsTemplate
		Shirt.ShirtTemplate = script.Parent.Uniform.LR.Shirt.ShirtTemplate
	end
end)

Change this:
local Character = Player:WaitForChild("Character")
To this:
local Character = Player.Character:wait()

By saying :WaitForChild(), key word ‘child’, you are asking Roblox to wait for a child of the player, which the character object is not.

1 Like

This didn’t work, it throws this error.

My bad. Make the :wait() lowercase. Sorry.

Still nothing, the clothes are not put on the player.

image

Can you show me what you did? Also, where are you getting the shirt ID?

I am not getting the shirt ID, there is a folder with pants and a shirt.

Can you showed me your new code?

script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local Character = Player.Character:wait()

	if Player:GetRankInGroup(4789894) <= 8 then
		local Shirt = Character.Shirt
		local Pants = Character.Pants

		if not Shirt then
			Shirt = Instance.new("Shirt", Character)
		end

		if not Pants then
			Pants = Instance.new("Pants", Character)
		end	

		Pants.PantsTemplate = script.Parent.Uniform.LR.Pants.PantsTemplate
		Shirt.ShirtTemplate = script.Parent.Uniform.LR.Shirt.ShirtTemplate
	end
end)
script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local Character = Player.Character or Player.CharacterAdded:Wait()

	if Player:GetRankInGroup(4789894) <= 8 then
		local Shirt = Character.Shirt
		local Pants = Character.Pants

		if not Shirt then
			Shirt = Instance.new("Shirt", Character)
		end

		if not Pants then
			Pants = Instance.new("Pants", Character)
		end	

		Pants.PantsTemplate = script.Parent.Uniform.LR.Pants.PantsTemplate
		Shirt.ShirtTemplate = script.Parent.Uniform.LR.Shirt.ShirtTemplate
	end
end)

This will work for you. The character is not a descendant of the player, it’s actually parented to workspace. Use Player.Character or Player.CharacterAdded:Wait() when looking for the character.

Player.Character:wait() is always going to error.

1 Like

Dude, you should be doing it this way. Don’t spread false information like that.

local Character = Player.Character or Player.CharacterAdded:Wait()
1 Like

I literally just came back, about to type this. No need to be rude, I just messed up.

Thank you, also thanks to @TestAccount563344 for the information.

I think you could just do something like this…

script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if not Player then
        return -- if failed to find the player by character, return and don't continue
    end

    -- :GetPlayerFromCharacter didn't return nil with hit.parent
    -- meaning that hit.parent is the player's character
	local Character = hit.Parent

	if Player:GetRankInGroup(4789894) <= 8 then
		local Shirt = Character.Shirt
		local Pants = Character.Pants

		if not Shirt then
			Shirt = Instance.new("Shirt", Character)
		end

		if not Pants then
			Pants = Instance.new("Pants", Character)
		end	

		Pants.PantsTemplate = script.Parent.Uniform.LR.Pants.PantsTemplate
		Shirt.ShirtTemplate = script.Parent.Uniform.LR.Shirt.ShirtTemplate
	end
end)

Also doing Player.Character or Player.CharacterAdded:Wait() will error if :GetPlayerFromCharacter fails

1 Like