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

Button Script not working?

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

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)

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