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

This Only Works In Studio?

Asked by 10 years ago

This code is supposed to change the players pants and shirt

function onTouch(r) -- when the brick is touched
    wait(1) -- waits one second
    local p = r.Parent:WaitForChild("Pants") -- finds the pants from the player who touched it
    local s = r.Parent:WaitForChild("Shirt") --finds the shirt
    if (p ~= nil) then -- checks if it exists
        p.PantsTemplate = "rbxassetid://146138748" -- changes the pants
        s.ShirtTemplate = "rbxassetid://145609726" -- changes the shirt
    end -- ends
end -- ends

script.Parent.Touched:connect(onTouch) -- connects
0
Is there anything in the output? If not, try placing a print after the If on line 5 and observe the console in-game to see if the logic checks out. However, I'm a bit confused -- why do you only replace the pants AND shirt if the pants exist? RoboFrog 400 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

It seems that you should check for a humanoid and make the script more efficient. If there was a part that touched the block that wasn't a part of a player, your code would have brought up an error.

script.Parent.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
  wait(0.5) 
local pants = hit.Parent:FindFirstChild("Pants")
if pants then
pants.PantsTemplate = "rbxassetid://146138748"
end
local shirt = hit.Parent:FindFirstChild("Shirt")
if shirt then
shirt.ShirtTemplate = "rbxassetid://145609726"
    end
end
end)

I hope you understand!

Don't forget to accept this as the answer!

Ad

Answer this question