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

ClickDetector Script help? [closed]

Asked by
F_lipe 135
10 years ago
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.

0
The name of the script is 'Yo' Just to let you know. F_lipe 135 — 10y

Locked by 2eggnog, Perci1, and TofuBytes

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
10 years ago

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)
0
I got it working thanks for the help :) F_lipe 135 — 10y
Ad
Log in to vote
-4
Answered by
Subbix -5
10 years ago

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

1
MouseClick is a valid event for ClickDetectors. 2eggnog 981 — 10y