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
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)