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

How do I change the color of a PointLight via color of a GUI button?

Asked by
Spooce 78
9 years ago

I want the color of the PointLight the same color of the GUI TextButton. Help?

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

mu has the correct answer, but his code is inefficient:

local light = workspace.Part.PointLight --set this to the PointLight object
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame --set this to the GUI object you want to draw from.

gui.Changed:connect(function()
    light.Color = gui.BackgroundColor3 --Or, as mu said, TextColor3 or BorderColor3
end)
1
Lmao, I just wrote the first thing that came to mind...coroutines Muoshuu 580 — 9y
0
I could bash that, since using coroutine.wrap() inline is ugly. Not to say a resume wrapping a create wrapping a function is any less ugly but I digress. adark 5487 — 9y
Ad
Log in to vote
2
Answered by
Muoshuu 580 Moderation Voter
9 years ago

Assuming you have the Script in the button and a PointLight in a part in the workspace

local Light=workspace.Part.PointLight
coroutine.wrap(function()
    while wait() do
        Light.Color=script.Parent.BackgroundColor3 --Or TextColor3, BorderColor3, etc...
    end
end)()

Answer this question