local textBoxA = script.Parent.RedValue local textBoxB = script.Parent.GreenValue local textBoxC = script.Parent.BlueValue local function onFocusLost(enterPressed, _inputObject) if enterPressed then local textA = textBoxA.Text local textB = textBoxB.Text local textC = textBoxC.Text script.Parent.ImageLabel.ImageColor3 = Color3.fromRGB(textA,textB,textC) end end textBoxA.FocusLost:Connect(onFocusLost) textBoxB.FocusLost:Connect(onFocusLost) textBoxC.FocusLost:Connect(onFocusLost) local RepStorageService = game:GetService("ReplicatedStorage") local MoodLightingEvent = game.ReplicatedStorage:FindFirstChild("MoodLightEvent") script.Parent.Execute.MouseButton1Click:Connect(function(textA,textB,textC) MoodLightingEvent:FireServer(textA,textB,textC) print("Server fired!") end)
In this script I am attempting to pull the values out of the function called onFocusLost and parse them through the rest of script so they can be used in a remote event, problem is it returns the value in the function as nil, nil, nil whenever I do anything which I normally would assume would get the values out, such as a return.
I can not define the variables globally for the script simply because the textbox doesn't allow me too.
How can I get the values out of my function to pass them into my remote event?
Create another function to get the text of the textbox; you can then use return
so you can use them outside the function.
local textBoxA = script.Parent.RedValue local textBoxB = script.Parent.GreenValue local textBoxC = script.Parent.BlueValue local function GetText(textA, textB, textC) return textA.Text, textB.Text, textC.Text end local function onFocusLost(enterPressed, _inputObject) if enterPressed then local textA, textB, textC = GetText(textBoxA, textBoxB, textBoxC) script.Parent.ImageLabel.ImageColor3 = Color3.fromRGB(textA,textB,textC) end end textBoxA.FocusLost:Connect(onFocusLost) textBoxB.FocusLost:Connect(onFocusLost) textBoxC.FocusLost:Connect(onFocusLost) local RepStorageService = game:GetService("ReplicatedStorage") local MoodLightingEvent = game.ReplicatedStorage:FindFirstChild("MoodLightEvent") script.Parent.Execute.MouseButton1Click:Connect(function() local textA, textB, textC = GetText(textBoxA, textBoxB, textBoxC) MoodLightingEvent:FireServer(textA,textB,textC) print("Server fired!") end)