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)

3 comments
Another thing is the long script.Parent lines are for the script so that it can locate the Shirt and Configuration file since I can't place them in the text button where my script is.
Why do you use script when you can just access workspace directly?
MouseButton1Click cannot return the mouse to you using parameters. So remove the mouse part.