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

I'm trying to make a script with ClickDetector but it doesn't work, how do I fix it?

I'm trying to make a script where a button opens door

the code

local part = script.Parent
part.Parent = game.Workspace
local part2 = game.Workspace.Model.Part2
part2.Parent = game.Workspace.Model
local clickdetector = workspace.Model.Part.ClickDetector

local function onMouseClick()
	part2.Transparency = 0.5
	part2.CanCollide = false
end

clickdetector.MouseClick:connect(onMouseClick)

'Part is not valid member of Model' there is no other models in the studio and the Part in the model is named Part

2 comments

0

have you tried workspace.Model:WaitForChild("Part").ClickDetector?

0

Why are you setting part2's parent to Model when it's parent is already Model?

1 answer

Try:

local part = script.Parent
part.Parent = game.Workspace
local part2 = game.Workspace.Model:WaitForChild("Part2")
part2.Parent = game.Workspace.Model
local clickdetector = workspace.Model.Part.ClickDetector

local function onMouseClick()
    part2.Transparency = 0.5
    part2.CanCollide = false
end

clickdetector.MouseClick:connect(onMouseClick)

1 comment

0

Now local clickdetector = workspace.Model.Part.ClickDetector doesn't work, (Part is not valid member of Model) I've tried WaitForChild on that one too

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