Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

problem with this script changing both TextColor?

Asked by 7 years ago

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
0
tab your code properly. BlueTaslem 18071 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
it worked but i dont understand the math part because i hate math :P AwesomeSauce666556 0 — 7y
0
there's no accept answer for some reason AwesomeSauce666556 0 — 7y
0
r, g, b has a max of 255. the color3 works from 0-1 so we just need to scale rgb to color3 range. User#5423 17 — 7y
0
There should be one on the righ or you can just upvote i dont mind User#5423 17 — 7y
Ad

Answer this question