Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

[SOLVED]Changing a OnTouch to a OnClick?

Asked by 9 years ago

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)

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. Ninjaruaz 22 — 9y
0
Why do you use script when you can just access workspace directly? NotsoPenguin 705 — 9y
0
MouseButton1Click cannot return the mouse to you using parameters. So remove the mouse part. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by
Wizzy011 245 Moderation Voter
9 years ago

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!

0
Thanks! Ninjaruaz 22 — 9y
Ad

Answer this question