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

Light changes to black even if the code itself works?

Asked by 6 years ago
Edited 6 years ago

I suppose its something to do with the beam. So basically there's a GUI that controls the Lighting System, and once you click on that GUI, another GUI pops up and lets you type in the respective Red, Green and Blue values. Now, the system works, but every time I try to enter different values, the light changes to the default value (0,0,0 black). Is there anything wrong?

local r = script.Parent:WaitForChild("R")
local rvalue = r.Text
local g = script.Parent:WaitForChild("G")
local gvalue = g.Text
local b = script.Parent:WaitForChild("B")
local bvalue = b.Text
local ent = script.Parent:WaitForChild("ent")

function UpdateColor()
local system = workspace["Airbus A320 by FlightPlan (PAID)"]:FindFirstChild("LightSystem")
local part2 = system.LightPart2
local part = system.LightPart
local beam = part.Beam
local light = part.SurfaceLight
local color1 = Color3.fromRGB(rvalue,gvalue,bvalue)
local color2 = Color3.fromRGB(rvalue,gvalue,bvalue)

part.Color = Color3.fromRGB(rvalue,gvalue,bvalue)
part2.Color = Color3.fromRGB(rvalue,gvalue,bvalue)
beam.Color = ColorSequence.new(color1,color2)
light.Color = Color3.fromRGB(rvalue,gvalue,bvalue)
script.Parent.Parent:Destroy()







end

ent.MouseButton1Click:Connect(UpdateColor)



Answers are appreciated!

EDIT: Answered by kingdom5



function UpdateColor() local r = script.Parent:WaitForChild("R") local rvalue = tonumber(r.Text) local g = script.Parent:WaitForChild("G") local gvalue = tonumber(g.Text) local b = script.Parent:WaitForChild("B") local bvalue = tonumber(b.Text) local ent = script.Parent:WaitForChild("ent") local system = workspace["Airbus A320 by FlightPlan (PAID)"]:FindFirstChild("LightSystem") local part2 = system.LightPart2 local part = system.LightPart local beam = part.Beam local light = part.SurfaceLight local color1 = Color3.fromRGB(rvalue,gvalue,bvalue) local color2 = Color3.fromRGB(rvalue,gvalue,bvalue) part.Color = Color3.fromRGB(rvalue,gvalue,bvalue) part2.Color = Color3.fromRGB(rvalue,gvalue,bvalue) beam.Color = ColorSequence.new(color1,color2) light.Color = Color3.fromRGB(rvalue,gvalue,bvalue) script.Parent.Parent:Destroy() end script.Parent.ent.MouseButton1Click:Connect(UpdateColor)
0
What I mean by the code itself works is that The code still runs, though the light's color is always black. Syntax_404 37 — 6y
0
Tha variabel are set at the top of your code they never change. You also should be using a number and not a string. User#5423 17 — 6y
0
The reason I used a string, and not a number is because it can't be directly referred because how would the script know the number the user typed in? And by your first statement, does that mean I have to update the variables after the function is called? Syntax_404 37 — 6y
1
you can use http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#tonumber and make sure to get the new values in the function User#5423 17 — 6y

Answer this question