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

Whats wrong with this Unlock Gui?

Asked by 8 years ago

Whats wrong with this? Unlock Gui shows up at 100 and will go to 250 after the value is between 101 and 200 but its now working..

wait(5)
sound=script.Parent.Sound
player = script.Parent.Parent.Parent
unlock = player.leaderstats.Tires

while true do
wait(0.5)
    if unlock.Value == 100 then
        script.Parent.GuiUnlock.Visible = true
        sound:play()
        wait(5)
        script.Parent.GuiUnlock.Visible = false
    repeat wait() until unlock.Value == 101 else 102 else 103 else 104 else 105 else 106 else 107 else 108 else 109 else 110 else 120 else 130 else 140 else 150 else 160 else 170 else 180 else 190 else 200
    elseif unlock.Value == 250 then
        script.Parent.GuiUnlock.Visible = true
        sound:play()
        wait(5)
        script.Parent.GuiUnlock.Visible = false
    repeat wait() until unlock.Value == 251 else 252 else 253 or 254 or 255 or 256 or 257 or 258 or 259 or 260 or 270 or 280 or 290 or 300 or 310 or 320 or 330 or 340 or 350
    elseif unlock.Value == 500 then
        script.Parent.GuiUnlock.Visible = true
        sound:play()
        wait(5)
        script.Parent.GuiUnlock.Visible = false
    repeat wait() until unlock.Value == 501 or 502 or 503 or 504 or 505 or 506 or 507 or 508 or 509 or 510 or 520 or 530 or 540 or 550 or 560 or 570 or 580 or 590 or 600
    elseif unlock.Value == 700 then
        script.Parent.GuiUnlock.Visible = true
        sound:play()
        wait(5)
        script.Parent.GuiUnlock.Visible = false
    repeat wait() until unlock.Value == 701 or 702 or 703 or 704 or 705 or 706 or 707 or 708 or 709 or 710 or 720 or 730 or 740 or 750 or 760 or 770 or 780 or 790 or 800
    elseif unlock.Value == 1200 then
        script.Parent.GuiUnlock.Visible = true
        sound:play()
        wait(5)
        script.Parent.GuiUnlock.Visible = false
    repeat wait() until unlock.Value == 1201 or 1202 or 1203 or 1204 or 1205 or 1206 or 1207 or 1208 or 1209 or 1210 or 1220 or 1230 or 1240 or 1250 or 1260 or 1270 or 1280 or 1290 or 1300
    end
end

0
wat? Tesouro 407 — 8y

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

This garble:

repeat wait() until unlock.Value == 101 else 102 else 103 else 104 else 105 else 106 else 107 else 108 else 109 else 110 else 120 else 130 else 140 else 150 else 160 else 170 else 180 else 190 else 200

Is improper syntax.

else is used in if statements like so:

if CONDITIONAL == true then
    -- codeblock
elseif CONDITIONAL == true then
    -- codeblock
else
    -- if neither conditional was true run this codeblock
end

Also, you are making a very common mistake with the use of or. In order to use or with conditionals, you need to rewrite the ==

For example:

if x == 3 or 2 then -- This is incorrect
    -- code
end

This is how the machine interprets it: Is x == 3 true? If not , is 2 true? If either are true, run code.

The problem here is you are checking if 2 is true, when you should be checking to see if x == 2is true.

Let's rewrite it now in proper syntax:

if (x == 3) or (x == 2) then -- Parentheses aren't necessary. I put them there so you can see the two different conditionals that are being checked

    -- run code
end

However, your code has a lot of unnecessary stuff going on. This garble is highly unnecessary:

501 or 502 or 503 or 504 or 505 or 506 or 507 or 508 or 509 or 510 or 520 or 530 or 540 or 550 or 560 or 570 or 580 or 590 or 600

In order to make your code have a range, or in other words, you want to find if

501 <= x <= 600

is true, you can do something like the following:

local x = 510
if (x >= 501) and (x <= 600) then -- Again, optional parentheses I put there to show the two conditionals

    -- code

end

However, I notice in your code your ors jump a little bit.

507 or 508 or 509 or 510 or 520 or 530

If you do not have ranges like I was talking about, you can put the values you are looking for into a table and check to see if x or unlock.Valueis in that table.

local set1 = {107, 108, 109, 110, 120, 130, 140} -- I didn't put in all the values

local function ValueIsInSet ( Value, set )
    for _, v in pairs(set) do
        if v == Value then
            return true
        end
    end
    return false
end
 --[[ If the script has not returned true, that means that no number in the loop made the function return, and it will therefore run the part that makes it return false. If a value matches though, the function will return true, and it will never make it to the line of the function that returns false. ]]

The above function can be called like so:

if ValueIsInSet ( unlock.Value, set1 ) then
    -- code
end

Good luck!

0
Thanks this gone help me alot! minetrackmania 186 — 8y
Ad

Answer this question