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

ClickDetector Script help?

local Lamp = script.Parent
local function onMouseClick(Player)
	print("Lamp is now on")
	if script.Parent.PointLight == nil then
		Point = Instance.new("PointLight")
		Point.Parent = script.Parent
	end
end
Lamp.MouseClick:connect(onMouseClick)


This is my output

19:37:18.907 - PointLight is not a valid member of ClickDetector 19:37:18.907 - Script 'Workspace.Lamp.ClickDetector.Yo', Line 4 19:37:18.908 - Stack End 19:37:18.909 - Disconnected event because of exception

What have I done wrong in this script? If you need more info just ask.

1 comment

0

The name of the script is 'Yo' Just to let you know.

2 answers

✓ Accepted answer

Try this. Your mistakes are described in the comments.

local Lamp = script.Parent.Parent --script.Parent is the ClickDetector, not the lamp.
local function onMouseClick(Player)
    print("Lamp is now on")
    if Lamp:FindFirstChild("PointLight") == nil then --Use FindFirstChild to avoid errors.
        Point = Instance.new("PointLight")
        Point.Parent =Lamp --Parenting the light to a ClickDetector probably won't work.
    end
end
script.Parent.MouseClick:connect(onMouseClick)

1 comment

0

I got it working thanks for the help :)

You really did it wrong... MouseClick is supposed to be MouseButton1Down

1 comment

1

MouseClick is a valid event for ClickDetectors.

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