Hey, I'll just be adding a few points to @nanaluk01 's answer now.
Lets take his script now, since he pretty much fixed the code...
local reward = nil
script.Parent.MouseButton1Click:connect(function()
if script.Parent.Parent.Input.Text == "Sneaky" or script.Parent.Parent.Input.Text == "sneaky" then
script.Parent.Text = "Accepted"
wait(5)
script.Parent.Text = "Submit"
elseif script.Parent.Parent.Input.Text ~= "Sneaky" and script.Parent.Parent.Input.Text ~= "sneaky" then
script.Parent.Parent.Input.Text = ""
script.Parent.Text = "Declined"
wait(1)
script.Parent.Text = "Submit"
end
end)
Seems cool right? Let's dig some more gems...
On line 3, ever heard of variables? :) You are trying to rewrite a ton of code again and again. It's alright! people make such mistakes, so don't feel bad and lets get on with this.
Maybe we could change the code like this?
local inputbox = script.Parent.Parent.Input
script.Parent.MouseButton1Click:connect(function()
if inputbox.Text == "Sneaky" or inputbox.Text == "sneaky" then
script.Parent.Text = "Accepted"
wait(5)
script.Parent.Text = "Submit"
elseif inputbox.Text ~= "Sneaky" and inputbox.Text ~= "sneaky" then
script.Parent.Parent.Input.Text = ""
script.Parent.Text = "Declined"
wait(1)
script.Parent.Text = "Submit"
end
end)
ALRIGHTY! That seems nice, but wait, there's still something! You seem to kinda make things a bit large with exaggerating the code... Let's buckle it down a little. :3
local inputbox = script.Parent.Parent.Input
script.Parent.MouseButton1Click:connect(function()
if string.lower(inputbox.Text) == string.lower() then
script.Parent.Text = "Accepted"
wait(5)
script.Parent.Text = "Submit"
elseif inputbox.Text ~= "Sneaky" and inputbox.Text ~= "sneaky" then
script.Parent.Parent.Input.Text = ""
script.Parent.Text = "Declined"
wait(1)
script.Parent.Text = "Submit"
end
end)
Whoo! We did it! :D
So, what does this string.lower("some STRING here") do?
It basically turns the given string to lower case, so we don't have to deal with checking the string multiple times like "Sneaky", "sneaky". This is very useful function!
Learn more about it (and other functions) here !
http://wiki.roblox.com/index.php?title=Global_namespace/String_manipulation#string.lower
Okay, now this code can also get squeezed a bit more, but why should I do all the stuff when you're around to finish it! :D
Hope I helped !
1 comment
This is literally almost exactly what I posted xD