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

Button Script not working?

Asked by
F_lipe 135
10 years ago
1local x = script.Parent:FindFirstChild("PointLight")
2local function onMouseClick(Player)
3    print("Lamp is now on")
4    local x = script.Parent:FindFirstChild("PointLight")
5    if x.Enabled == false then
6    x.Enabled = true   
7    end
8end
9x.MouseClick:connect(onMouseClick)

So I wanted this to make it to where when you clicked the lamp it would enable the pointlight inside the lamp. I ran into some errors it seems, if you could tell me what I did wrong I'd be really greatful. (This is my first time using click detectors and making scripts for them)

1 answer

Log in to vote
0
Answered by 10 years ago

You're making the point light have to be clicked, not the button to click it on. Make X = something different.

01local x = script.Parent
02local light = script.Parent:FindFirstChild("PointLight")
03local function onMouseClick(Player)
04    print("Lamp is now on")
05    local light = script.Parent:FindFirstChild("PointLight")
06    if light.Enabled == false then
07    light.Enabled = true
08    end
09end
10x.MouseClick:connect(onMouseClick)
Ad

Answer this question