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 fix this Clothes Changer?

Everything works fine in studio but when in game it wont work, please help, its suppose to change your clothes when you chat

-- Scripted By Architectix --

game.Players.PlayerAdded:connect(function(Player)
	wait(1)
	Player.Chatted:connect(function(chat)
	wait(1)
	local Char = game.Players.LocalPlayer.Character --  this is the line that keeps messing up --
	-------------------------------------------------
		if (chat == "GPDUni" or "GPDUniform") then 
			if Char ~= nil then
	local Shirt = Char:WaitForChild("Shirt")
	Shirt.ShirtTemplate = "rbxassetid://347880617"
	local Pants = Char:WaitForChild("Pants")
	Pants.PantsTemplate = "rbxassetid://337925943"
			end
		end
----------------------------------------------------
	end)
end)

2 answers

✓ Accepted answer

To use PlayerAdded in a LocalScript is used differently then how you would normally use it in a ServerScript... In a LocalScript you have to make Pairs, iterating through all the players and also you have to use the :GetService method. Here is some more information on as to how you would use a PlayerAdded event in a LocalScript...

http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerAdded

Thank you for reading my answer I hope I helped :D!

  1. LocalPlayer only works with Local Scripts. This is probably a Script that's meant to from the server.
  2. Since PlayerAdded returns the player, just use that instead of LocalPlayer.
-- Scripted By Architectix --

game.Players.PlayerAdded:connect(function(Player)
    wait(1)
    Player.Chatted:connect(function(chat)
    wait(1)
    local Char = Player.Character
        if (chat == "GPDUni" or "GPDUniform") then 
            if Char ~= nil then
    local Shirt = Char:FindFirstChild("Shirt") or Instance.new("Shirt", Char)
    Shirt.ShirtTemplate = "rbxassetid://347880617"
    local Pants = Char:FindFirstChild("Pants") or Instance.new("Pants", Char)
    Pants.PantsTemplate = "rbxassetid://337925943"
            end
        end
----------------------------------------------------
    end)
end)

2 comments

1

it still won't work in game though and i tried starting a server and i didn't get any errors

1

The problem is that the player that spawns when you start a server don't have shirts or pants to begin with, so you can't just use :WaitForChild() (because it will yield forever). I edited the script to accommodate this.

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