How do you get the text from a textbox

I am trying to get the value of a textbox so I can input it into color3 and change the color of a brick

local brick = game.Workspace.Part

local red = game.StarterGui.ScreenGui.ColorPicker.R --these are the text boxes
local green = game.StarterGui.ScreenGui.ColorPicker.G
local blue = game.StarterGui.ScreenGui.ColorPicker.B


function Bread(Player)

	local gamepassid = 11042304
	local Player = game:GetService("Players").LocalPlayer
	 if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,gamepassid) then
		
		brick.Color = Color3.fromRGB(red.Text,green.Text,blue.Text) print(red.Text,green.Text,blue.Text)
			
	else
		
		print("No gamepass detected... Prompting Purchase") 
		game:GetService("MarketplaceService"):PromptGamePassPurchase(Player,gamepassid) 
	end
	
	
	
	
end

script.Parent.MouseButton1Click:Connect(Bread)

put


local red = game.StarterGui.ScreenGui.ColorPicker.R
local green = game.StarterGui.ScreenGui.ColorPicker.G
local blue = game.StarterGui.ScreenGui.ColorPicker.B

into the function so that it can get the updated text, not the default text.

that still returns the text as " " and it sets the color3 value to 0,0,0

1 Like

You need to get it from the player’s PlayerGui, not the StarterGui. You can just use the Text property to read the colors.

local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local brick = game.Workspace.Part

local red = playerGui.ScreenGui.ColorPicker.R
local green = playerGui.ScreenGui.ColorPicker.G
local blue = playerGui.ScreenGui.ColorPicker.B

function Bread(Player)

	local gamepassid = 11042304
	local Player = game:GetService("Players").LocalPlayer
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,gamepassid) then
		brick.Color = Color3.fromRGB(red.Text,green.Text,blue.Text) 
		print(red.Text,green.Text,blue.Text)
	else
		
		print("No gamepass detected... Prompting Purchase") 
		game:GetService("MarketplaceService"):PromptGamePassPurchase(Player,gamepassid) 
	end
end

script.Parent.MouseButton1Click:Connect(Bread)
2 Likes

In, “brick.Color = Color3.fromRGB(red.Text,green.Text,blue.Text)” You’re getting the string, try converting it to a number with tonumber()

Example:

local red = tonumber(game.StarterGui.ScreenGui.ColorPicker.R.Text)
local green = tonumber(game.StarterGui.ScreenGui.ColorPicker.G.Text)
local blue = tonumber(game.StarterGui.ScreenGui.ColorPicker.B.Text)
...

brick.Color = Color3.fromRGB(red,green,blue)

Do game.Players.LocalPlayer.PlayerGui.mygui instead of using StarterGui.

1 Like

That worked!, thank you for your help

1 Like