Recently I’ve been creating a new Menu GUI for my game and i want that the name of the player to change colors every time he/she opens the menu.
What i mean by that is : https://gyazo.com/da0e8eb2bc928f13f1c6ae890a90801d
The name of the player should change every time he opens the menu
Here is the script :
--Defining Things
local OpenButton = script.Parent.OpenMenu
local CloseButton = script.Parent.CloseMenu
local Menu = script.Parent
local IsOpen = false
local NameText = script.Parent.Name
local Colors = {
Color3.new(255,255,255),
Color3.new(0,85,0),
Color3.new(170, 255, 0),
Color3.new(170, 85, 127)
}
Menu.Position = UDim2.new(-0.208, 0,-0.163, 0) --Start Position
OpenButton.MouseButton1Click:Connect(function()
if IsOpen == false then
Menu:TweenPosition(
UDim2.new(0, 0,-0.163, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1.3, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
IsOpen = true
NameText.TextColor3 = Color3.new(math.random(Colors))
end
end)
CloseButton.MouseButton1Click:Connect(function()
if IsOpen == true then
Menu:TweenPosition(
UDim2.new(-0.208, 0,-0.163, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
IsOpen = false
end
end)
I tried in many other ways to fix this but none of them worked.
The immediate problem I see is you’re creating the color wrong. Using Color3.new takes in a rgb but with all values from 0 to 1. Change them to Color3.fromRGB and see if that fixes it. fromRGB takes rgb from 0 to 255. You’re also instantiating a new color with a random value taking in a table? I think you mean to do
local OpenButton = script.Parent.OpenMenu
local CloseButton = script.Parent.CloseMenu
local Menu = script.Parent
local IsOpen = false
local NameText = script.Parent.Name
local Colors = {
Color3.fromRGB(255,255,255),
Color3.fromRGB(0,85,0),
Color3.fromRGB(170, 255, 0),
Color3.fromRGB(170, 85, 127)
}
i defined IsOpen above. I also tried moving it before the function starts and got the same results
You see the variable “local NameText = script.Parent.Name”
change that to
local NameText = script.Parent.PlayerName
and then change the textbox to PlayerName - Atm this script is getting the name of the textbox parent and trying to change the color of the parent of the textbox as Name is a property of everything so your calling that property rather than the textbox called “Name”
I do not want a totally random color, which is why i created a table of a few test colors to see if the script works. However , every time i open the menu i get this error
[Players.Reinellex.PlayerGui.NewMenu.MainFrame.Open/Close Menu:25: attempt to get length of a userdata value]
You edited the post and i didn’t noticed. My bad!
Now i corrected my mistake and i get the same error.
local OpenButton = script.Parent.OpenMenu
local CloseButton = script.Parent.CloseMenu
local Menu = script.Parent
local NameText = script.Parent.Name
local Colors = Color3.new(math.random(), math.random(), math.random())
print(Colors)
Menu.Position = UDim2.new(-0.208, 0,-0.163, 0) --Start Position
IsOpen = false
OpenButton.MouseButton1Click:Connect(function()
if IsOpen == false then
Menu:TweenPosition(
UDim2.new(0, 0,-0.163, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1.3, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
IsOpen = true
NameText.TextColor3 = Colors[math.random(#Colors)]
end
end)
I am so sorry for not understanding.
Also the Colors are printed and are, as you said, numbers between 0 and 1
--Defining Things
local OpenButton = script.Parent.OpenMenu
local CloseButton = script.Parent.CloseMenu
local Menu = script.Parent
local NameText = script.Parent.Name
local Colors = Color3.new(math.random(), math.random(), math.random())
print(Colors)
Menu.Position = UDim2.new(-0.208, 0,-0.163, 0) --Start Position
IsOpen = false
OpenButton.MouseButton1Click:Connect(function()
if IsOpen == false then
Menu:TweenPosition(
UDim2.new(0, 0,-0.163, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1.3, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
IsOpen = true
NameText.TextColor3 = Colors
end
end)
CloseButton.MouseButton1Click:Connect(function()
if IsOpen == true then
Menu:TweenPosition(
UDim2.new(-0.208, 0,-0.163, 0), --End Position
"InOut", --Easing Direction (where the tweeening will happen)
"Quart", --Easing Style
1, --Time in seconds
false, --Override other tweens
nil, --Callback (function)
false --Return
)
IsOpen = false
end
end)
Oh! I just realised that the name of the TextLabel was the same with the Property name . I am so so sorry for this.
I’ve also fixed the random colors by replacing local Colors inside the function. Thank you E44 and ELECTRO for helping