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

function script involving ClickDetector not working?

Asked by 8 years ago
x = game.workspace.Part
function onClicked(z)
    x.Transparency = 1
    x.CanCollide = false
    x.BrickColor = BrickColor.new("Really green")
    wait (5)
    x.Transparency = 0
    x.CanCollide = true
    x.BrickColor = BrickColor.new("Really red")

end
game.Workspace.ClickDetector.MouseClick:connect(onClicked)

I added a clickdetector into the part as well but when I click it the Part doesnt change at all

0
yeah it worked, but I dont get it. what did I do wrong in my script? only the names? trashtalked 5 — 8y
0
You connected the function it to the ClickDetector in the workspace rather than the one in the part. IDidMakeThat 1135 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The problem is that the ClickDetector you are connecting the function to is not in the part. You need to put it in the part, then change the script accordingly:

local part = script.Parent -- This assumes the script is inside the part.
function onClicked()
    part.Transparency = 1
    part.CanCollide = false
    part.BrickColor = BrickColor.new("Really green")
    wait (5)
    part.Transparency = 0
    part.CanCollide = true
    part.BrickColor = BrickColor.new("Really red")
end
part.ClickDetector.MouseClick:connect(onClicked)

Also, I would recommend using more descriptive variable names. It will make the script easier to understand.

Ad

Answer this question