I am trying to make a username button, and I'm not sure whats wrong with my script. I don't know if I messed up the colors or not.
if script.Parent.Text.CaptainAlien132 and MouseButton1Click:Connect(function() script.Parent.Parent.UserEnter then script.Parent.Parent.UserEnter.BackgroundColor3 = "204, 255, 204" script.Parent.Confirmed.Play() end if script.Parent.Text = --Anything except my user I don't know how to do that part and MouseButton1Click:Connect(function() script.Parent.Parent.UserEnter then script.Parent.Parent.UserEnter.BackgroundColor3 = "255, 89, 89" script.Parent.Denied.Play() wait(.2) script.Parent.Parent.UserEnter.BackgroundColor3 = '54, 81, 81' end
I am a bit of a noob, so please go easy on me!
1) It is better to write code inside the main function, not in an
if
statement.2) Gui BackgroundColor3 takes Color3.new(value/255, value/255, value/255)
3) Indentation is required to make the code look neater.
4) Playing a sound is
:Play()
, not.Play()
5) Declaring variables always makes life easier. Rather than saying
if code == "Name then"
and so on, you could say,if code = codeValue then
to make life easier.6)
not
is used to check if the value is else. For ex,if text not= TextValue then
-- Declaration Section local player = game:GetService("Players").LocalPlayer local playerGui = player.PlayerGui local enterName = playerGui.MainGui.Frame.EnterName local goButton = playerGui.MainGui.Frame.Go local targetMessage = "CaptainAlien132" local debounce = false local confirmed = playerGui.MainGui.Frame.Confirmed -- Not too sure if this works local denied = playerGui.MainGui.Frame.Denied -- Same as above local confirmedColour = Color3.new(204/255, 255/255, 204/255) local deniedColour = Color3.new(255/255, 89/255, 89/255) local regularColour = Color3.new(54/255, 81/255, 81/255) -- Processing Section local function changeNames() if enterName.Text == targetMessage then if debounce then return end debounce = true enterName.BackgroundColor3 = confirmedColour enterName.Text = "Correct!" confirmed:Play() wait(1) enterName.Text = "Enter name Here" enterName.BackgroundColor3 = regularColour debounce = false else if debounce then return end debounce = true for number = 0, 2, 1 do enterName.BackgroundColor3 = deniedColour wait(0.15) enterName.BackgroundColor3 = regularColour wait(0.15) print (number) end denied:Play() wait() enterName.BackgroundColor3 = regularColour debounce = false end end -- Output Section goButton.MouseButton1Down:Connect(changeNames)
This is the link of the Hierarchy chart if you are unsure where all the variables are