When i press S, both the Continue and NewGame buttons turn white. but none of them turns back to the normal color, after you press W
what im trying to do is make a start screen gui that has a new game button and a continue button, that are selected with W (new game) or S(continue)
but when i press any button both of the text color turns white
local frame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.ImageLabel.Frame.Select function onKeyPress(inputObject) if inputObject.KeyCode == Enum.KeyCode.W then print("W was pressed") if frame.Position == UDim2.new (0.5, 0,0.559, 0) then frame.Position = UDim2.new(0.5, 0,0.5, 0) script.Parent.Parent.Continue.TextColor3 = Color3.new(27, 42, 53) script.Parent.Parent.NewGame.TextColor3 = Color3.new(255,255,255) end elseif inputObject.KeyCode == Enum.KeyCode.S then print("S was pressed") if frame.Position == UDim2.new(0.5, 0,0.5, 0) then frame.Position = UDim2.new(0.5, 0,0.559, 0) script.Parent.Parent.NewGame.TextColor3 = Color3.new(27, 42, 53) script.Parent.Parent.Continue.TextColor3 = Color3.new(255,255,255) end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
i also tried to put a changed function inside the button
local player = game.Players.LocalPlayer local frame = player.PlayerGui.ScreenGui.Frame.ImageLabel.Frame.Frame frame.Position.Changed:connect(function() if frame.Position == script.Parent.Position then script.Parent.TextColor3 = Color3.new(255,255,255) end end)
Output:
17:28:27.957 - Changed is not a valid member of UDim2
Color3 value range is from 0-1 so we need to divide by 255 as this is the max value for r,g,b.
You can still optimise this code:-
local frame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.ImageLabel.Frame.Select local gui = script.Parent.Parent -- just added this here so we dont repeate some code function onKeyPress(inputObject) if inputObject.KeyCode == Enum.KeyCode.W then print("W was pressed") if frame.Position == UDim2.new (0.5, 0,0.559, 0) then frame.Position = UDim2.new(0.5, 0,0.5, 0) gui.Continue.TextColor3 = Color3.new(27/255, 42/255, 53/255) -- color 3 values range from 0-1 so we need to add /255 for the r,g,b gui.NewGame.TextColor3 = Color3.new(255/255,255/255,255/255) end elseif inputObject.KeyCode == Enum.KeyCode.S then print("S was pressed") if frame.Position == UDim2.new(0.5, 0,0.5, 0) then -- more repeated code frame.Position = UDim2.new(0.5, 0,0.559, 0) gui.NewGame.TextColor3 = Color3.new(27/255, 42/255, 53/255) -- you could remove this repeated code gui.Continue.TextColor3 = Color3.new(255/255,255/255,255/255) end end end game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Hope this helps, pls comment if you do not understand this code.