tyler09456
(RollMysts)
September 5, 2020, 3:52pm
#1
How do I fix this script? I’m trying to make it so when you enter the colour code into a GUI and click the button it will change the colour.
Current code:
local color = game.StarterGui.ScreenGui.SettingsFrame.TextBox.Text
local frame = game.StarterGui.ScreenGui.Click
local frame2 = game.StarterGui.ScreenGui.SettingsFrame
local frame3 = game.StarterGui.ScreenGui.Main
local frame4 = game.StarterGui.ScreenGui.Settings
script.Parent.MouseButton1Click:Connect(function()
frame.BackgroundColor3 = Color3.fromRGB(color)
end)
I know I most likely made a stupid mistake but i’m just not sure how to fix it.
Okay so to get the color code you have to first seperate the text in the color textbox
The way you do that is by using string.split
local segments = string.split(color, ",")
then you have to convert the segments from string to number and put them in to the color3.fromrgb
Color3.fromRGB(tonumber(segments[1]),tonumber(segments[2]),tonumber(segments[3]))
And also just so you know
the input has to be in this format r,g,b
tyler09456
(RollMysts)
September 5, 2020, 4:05pm
#3
Sadly that does not work… I’ve tried looking in output for errors but nothing so i’m very confused.
tyler09456
(RollMysts)
September 5, 2020, 4:06pm
#5
local color = game.StarterGui.ScreenGui.SettingsFrame.TextBox.Text
local frame = game.StarterGui.ScreenGui.Click
local frame2 = game.StarterGui.ScreenGui.SettingsFrame
local frame3 = game.StarterGui.ScreenGui.Main
local frame4 = game.StarterGui.ScreenGui.Settings
local segments = string.split(color, “,”)
script.Parent.MouseButton1Click:Connect(function()
frame.BackgroundColor3 = Color3.fromRGB(tonumber(segments[1]),tonumber(segments[2]),tonumber(segments[3]))
end)
Correct me if I’m wrong, but…
You shouldn’t be using game.StarterGui
. Instead, make a variable for the LocalPlayer
and get their PlayerGui
.
local player = game.Players.LocalPlayer
player:WaitForChild("PlayerGui") -- replace game.StarterGui with this line
2 Likes
Try this (With the fix that decodedMint talked about)
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local color = PlayerGui .ScreenGui.SettingsFrame.TextBox
local frame = PlayerGui.ScreenGui.Click
local frame2 = PlayerGui.ScreenGui.SettingsFrame
local frame3 = PlayerGui.ScreenGui.Main
local frame4 = PlayerGui.ScreenGui.Settings
script.Parent.MouseButton1Click:Connect(function()
local segments = string.split(color.Text, “,”)
frame.BackgroundColor3 = Color3.fromRGB(tonumber(segments[1]),tonumber(segments[2]),tonumber(segments[3]))
end)
1 Like
O, thank you for spotting that. I didn’t see it.
Good job
1 Like
tyler09456
(RollMysts)
September 5, 2020, 4:13pm
#10
Ok, i’ll do that now! Thanks for telling me.
1 Like
tyler09456
(RollMysts)
September 5, 2020, 4:16pm
#11
Looks like DevForum converted one of the characters in the script
make sure that is sais " instead of “
Its really hard to spot, but there is a difference
tyler09456
(RollMysts)
September 5, 2020, 4:20pm
#13
Yeah i’ve fixed that.
I’ve now got an issue where it can only be black and it does not matter what you put into it.
Try to print out what it sets the color3 to
so do this
local NewColor3 = Color3.fromRGB(tonumber(segments[1]),tonumber(segments[2]),tonumber(segments[3]))
print(NewColor3)
frame.BackgroundColor3 = NewColor3
What does it print out?
tyler09456
(RollMysts)
September 5, 2020, 4:24pm
#15
I’ve done that and here is the result:
**
**
What did you input in to the text box?
tyler09456
(RollMysts)
September 5, 2020, 4:26pm
#17
It does not matter what I put in, it always only fills the first part of the color code and leaves the other two , 's with 0 which most likely causes this.
Can i jump in to studio with you?
because i have no idea what is happening
tyler09456
(RollMysts)
September 5, 2020, 4:29pm
#19
Sure, add me on Roblox and i’ll get you on the studio.
tyler09456
(RollMysts)
September 5, 2020, 4:31pm
#20
You now have perms to edit, heres the game link: Place :) - Roblox
waystar69
(waystar)
September 5, 2020, 5:06pm
#21
script.parent.MouseButton1Clicked:Connect(function()
script.Parent.Color = Color3.fromRGB("Really Red")
(end)
Just make manual buttons, like Arsenal. Click the button, opens a frame up, then whatever thing you click, it clicks. It will always override the last color change.
Gooday!
Edit: It can be any color you’d like, just handpicked a example.