I recently got a script that lets me change the clothing of any player when it is touched, but I wanted to make it so that when a player clicks a GUI it changes the clothing! I tried moving the script into the text button and tried to convert it so that it will work. My changes didn't work sadly. What am I doing wrong and how can I fix it? Here is the original script:
function ch() script.Parent.Shirt.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Configuration.shirtId.Value-1 end script.Parent.Configuration.shirtId.Changed:connect(ch) function touch(hit) if hit.Parent:findFirstChild("Humanoid")~=nil and game.Players:findFirstChild(hit.Parent.Name)~=nil then if hit.Parent:findFirstChild("Shirt")==nil then shi=Instance.new("Shirt") shi.Parent=hit.Parent shi.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Configuration.shirtId.Value-1 shi.Name="Shirt" end hit.Parent.Shirt.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Configuration.shirtId.Value-1 end end script.Parent.Torso.touched:connect(touch)
Down here is the edited script I made to adapt the script to its new location
function ch() script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config.Shirt.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config.Configuration.shirtId.Value-1 end script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config.Configuration.shirtId.Changed:connect(ch) function onClick(mouse) if script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config:findFirstChild("Humanoid")~=nil and game.Players:findFirstChild(hit.Parent.Name)~=nil then if script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config:findFirstChild("Shirt")==nil then shi=Instance.new("Shirt") shi.Parent=hit.Parent shi.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config.Configuration.shirtId.Value-1 shi.Name="Shirt" end script.Parent.Shirt.ShirtTemplate="http://www.roblox.com/asset/?id="..script.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.Config.Configuration.shirtId.Value-1 end end script.Parent.MouseButton1Click:connect(onClick)
Firstly, you should use a LocalScript for what is being said below.
In your original script, wherever it says hit.Parent
, the should be replaced with game.Players.LocalPlayer.Character
, hit.Parent
would directly find the Character model of a player, whereas with a gui, you need to find this by going through the player.
Next, you don't need all these script.Parent.Parent.Parent.Parent.Parent
(and so on). You can just use workspace.Config.Configuration
script.Parent.MouseButton1Click:connect(onClick) was correct, as well as the function.
Hope this works out for you!