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

function script involving ClickDetector not working?

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

2 comments

0

yeah it worked, but I dont get it. what did I do wrong in my script? only the names?

0

You connected the function it to the ClickDetector in the workspace rather than the one in the part.

1 answer

✓ Accepted answer

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.

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