Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED]Changing a OnTouch to a OnClick?

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

0

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.

0

Why do you use script when you can just access workspace directly?

0

MouseButton1Click cannot return the mouse to you using parameters. So remove the mouse part.

1 answer

✓ Accepted answer

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!

1 comment

0

Thanks!

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