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

[Solved] Why is my 'end' order all screwed up?

Asked by 5 years ago
Edited 5 years ago

So I'm making a script (not to go into details) that uses multiple if and then statements with lots of elseif. It all seems to work until I try to end them. The end) paranthases has a red line under it but when I remove the ) it says it needs that ). So when I change the order the only thing that works makes a blue line under a bunch of things saying there unknown globally. ive seen this problem before and I'm not sure how to fix it any help would be greatly appreciated! Sorry it looks so complicated/messy. Code

local sell = script.Parent
local egg = game.Workspace.Egg
local board = game.Workspace

sell.Touched:Connect(function(part)
    if part.Name == "LeftFoot" or part.Name == "RightFoot" then
        if part.Parent:FindFirstChild("Egg") then 
            wait(2)
            local egg = part.Parent:FindFirstChild("Egg")
            if egg and egg.Handle.Type.Value == Common then
                player.leaderstats.Dollars.Value = player.leaderstats.Dollars.Value + 5 --the 'players' gets blue underlined
                wait(2)
            elseif egg and egg.Handle.Type.Value == Uncommon  then --the rares/uncommons etc get a blue underline
                player.leaderstats.Dollars.Value = player.leaderstats.Dollars.Value + 10
                wait(2)
            else    
                wait(2) 
            end
        else 
            wait(3) 
        end
    end --switching the order of these ends messes up the things above
end) --this ) has a red line
end) --when I switch it this gets a red underline rest is good
    end
        end 
0
Ow. User#21908 42 — 5y
0
^ and again I say Ow! User#21908 42 — 5y
0
i just had a lot of messages on a billboard gui ill try to clean it up but any ideas on the issue? JakeDaBeAat 13 — 5y

1 answer

Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
5 years ago

You put in a few useless lines of code, as well as putting ends in for just the else's when you only need an end after an if then or an elseif then statement.

local sell = script.Parent
local egg = game.Workspace.Egg
local board = game.Workspace

sell.Touched:connect(function(part)
    if part.Parent:findFirstChild("Egg") then
        wait(2)
        local egg = part.Parent:findFirstChild("Egg")
        if egg and egg.Handle.Type.Value == 'Common' then
            player.leaderstats.Dollars.Value = player.leaderstats.Dollars.Value + 5
            wait(2)
        elseif egg and egg.Handle.Type.Value == 'Uncommon'  then
            player.leaderstats.Dollars.Value = player.leaderstats.Dollars.Value + 10
                    wait(2)

            end
            wait(3)

        end
    end
end)
0
Though that wait(3) is useless too, should just have the wait at line 14 be wait(5) at that point. because you're just forcing the script to wait 3 seconds to fully end at this point. IcyEvil 260 — 5y
0
why did you change his FindFirstChild to findFirstChild User#19524 175 — 5y
0
I'm just used to using findFirstChild, when I re-wrote it I just automatically did it. findFirstChild still works, it's just deprecated. IcyEvil 260 — 5y
0
the wait(3) and some other useless lines are needed i removed a lot of thing like board.Text = "IMPORTANT STUFF" etc etc ill try this out tho JakeDaBeAat 13 — 5y
View all comments (5 more)
0
the apastrophes around uncommon and common, are they needed. They are a string values value JakeDaBeAat 13 — 5y
0
Yes, thats the only way for it to read what it says, unless you say local Common = 'Common' and local Uncommon = 'Uncommon' IcyEvil 260 — 5y
0
Ok so i think i fixed it the player was underlined because i didnt define it which i chaged to, local player = game.Players:GetPlayerFromCharacter(part.Parent) JakeDaBeAat 13 — 5y
0
@IcyEvil don't write code that just works. Write code that is both good code and works. Deprecated code is not good code, what if something happens to findFirstChild? Deprecated code is bound to break at any point, should roblox ever remove them User#19524 175 — 5y
0
@incapaz My bad, I'm just so used to writing it 'findFirstChild' but I'll remember to use the undeprecated version from now on. IcyEvil 260 — 5y
Ad

Answer this question