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
local x = script.Parent:FindFirstChild("PointLight")
local function onMouseClick(Player)
    print("Lamp is now on")
    local x = script.Parent:FindFirstChild("PointLight")
    if x.Enabled == false then
    x.Enabled = true    
    end 
end
x.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.

local x = script.Parent
local light = script.Parent:FindFirstChild("PointLight")
local function onMouseClick(Player)
    print("Lamp is now on")
    local light = script.Parent:FindFirstChild("PointLight")
    if light.Enabled == false then
    light.Enabled = true
    end
end
x.MouseClick:connect(onMouseClick)
Ad

Answer this question