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)
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.
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