If statement not working [SOLVED]

Hello, I have an issue where’s my script does work normally, but on the first elseif statement it does not work. I have looked for solutions, but i haven’t seen a problem like mine. I tried print(), but it didn’t print anything, that means if statement is false, but, how? i don’t understand. There’s also no errors in the output.

Don’t question the cash being in workspace. My game is multiplayer and has shared cash, and i thought this is a good way to do this.

This is the full script.

local prompt = script.Parent
local ingame = prompt.Parent.Parent.Ingame
local sign = ingame.Parent.FarmUpgraderSign
local sign2 = ingame.Parent.FarmUpgraderSign2

prompt.Triggered:Connect(function(plr)
 if ingame.Level.Value == 1 then
  if sign.Ingame.Current.Value == "Soul" then
   local char = game.Workspace:FindFirstChild(plr.Name)
    if char:FindFirstChild("Soul Piece") then
     local piece = char:FindFirstChild("Soul Piece")
     piece:Destroy()
     sign.Ingame.Needed.Value += 1
     sign.text.SurfaceGui.TextLabel.Text = "Need: 2 Soul Pieces ("..sign.Ingame.Needed.Value.."/2)"
     if sign.Ingame.Needed.Value >= 2 then
      sign.Ingame.Current.Value = "Cash"
      sign.text.SurfaceGui.TextLabel.Text = "Need: 2500$"
      prompt.ActionText = "Insert 2500$"
  elseif sign.Ingame.Current.Value == "Cash" then
   if game.Workspace.Cash.CashNumber.Value >= 2500 then
    game.Workspace.Cash.CashNumber.Value -= 2500
    ingame.Level.Value += 1
    sign.Ingame.Current.Value = "Soul"
    sign.Ingame.Needed = 4
    sign2.text.SurfaceGui.TextLabel.Text = "Farm Upgrader: Level "..ingame.Level.Value
    sign.text.SurfaceGui.TextLabel.Text = "Need 4 Soul Pieces (0/4)"
 elseif ingame.Level.Value == 2 then
   if sign.Ingame.Current.Value == "Soul" then
    local char = game.Workspace:FindFirstChild(plr.Name)
     if char:FindFirstChild("Soul Piece") then
      local piece = char:FindFirstChild("Soul Piece")
      piece:Destroy()
      sign.Ingame.Needed.Value += 1
      sign.text.SurfaceGui.TextLabel.Text = "Need: 4 Soul Pieces ("..sign.Ingame.Needed.Value.."/4)"
      if sign.Ingame.Needed.Value == 4 then
       sign.Ingame.Current.Value = "Cash"
       sign.text.SurfaceGui.TextLabel.Text = "Need: 5000$"
       prompt.ActionText = "Insert 5000$"
   end
  elseif sign.Ingame.Current.Value == "Cash" then
   if game.Workspace.Cash.CashNumber.Value >= 5000 then
    game.Workspace.Cash.CashNumber.Value -= 5000
    ingame.Level.Value += 1
    sign2.text.SurfaceGui.TextLabel.Text = "Farm Upgrader: Level "..ingame.Level.Value.." (MAX)"
    sign.text.SurfaceGui.TextLabel.Text = "Can't Upgrade Anymore"
    prompt:Destroy()
        end
       end
      end
     end
    end
   end
  end
 end
end)
2 Likes

Im assuming you show no errors in output? If so please show error lines.

I don’t have any errors in the output.

Right-click in the script editor and format all the code. It will fix the indentation, making everything a lot clearer/less misleading.

The main issue is things like this:

prompt.Triggered:Connect(function(plr)
 if ingame.Level.Value == 1 then
  if sign.Ingame.Current.Value == "Soul" then
   local char = game.Workspace:FindFirstChild(plr.Name)
    if char:FindFirstChild("Soul Piece") then
     local piece = char:FindFirstChild("Soul Piece")
     piece:Destroy()
     sign.Ingame.Needed.Value += 1
     sign.text.SurfaceGui.TextLabel.Text = "Need: 2 Soul Pieces ("..sign.Ingame.Needed.Value.."/2)"
     if sign.Ingame.Needed.Value >= 2 then
      sign.Ingame.Current.Value = "Cash"
      sign.text.SurfaceGui.TextLabel.Text = "Need: 2500$"
      prompt.ActionText = "Insert 2500$"

-- RIGHT HERE for example, `if sign.Ingame.Needed.Value >= 2 then` is attached to this elseif and it's not very obvious because your indentation is misleading

  elseif sign.Ingame.Current.Value == "Cash" then
1 Like

So do i just put an end? If yes, it still doesn’t work.

Code looks like this now.

if sign.Ingame.Needed.Value >= 2 then
					sign.Ingame.Current.Value = "Cash"
					sign.text.SurfaceGui.TextLabel.Text = "Need: 2500$"
					prompt.ActionText = "Insert 2500$"
                end
				elseif sign.Ingame.Current.Value == "Cash" then

What i think @Eestlane771 meant was format your code and repost it because there are so many if then statements its very hard to follow and find the error when the indentation is not aligned properly… and i would agree.

are you sure the condition is being met or the condition that activates the elseif is being met?

Alright then, here’s full formated code ig

local prompt = script.Parent
local ingame = prompt.Parent.Parent.Ingame
local sign = ingame.Parent.FarmUpgraderSign
local sign2 = ingame.Parent.FarmUpgraderSign2

prompt.Triggered:Connect(function(plr)
	if ingame.Level.Value == 1 then
		if sign.Ingame.Current.Value == "Soul" then
			local char = game.Workspace:FindFirstChild(plr.Name)
			if char:FindFirstChild("Soul Piece") then
				local piece = char:FindFirstChild("Soul Piece")
				piece:Destroy()
				sign.Ingame.Needed.Value += 1
				sign.text.SurfaceGui.TextLabel.Text = "Need: 2 Soul Pieces ("..sign.Ingame.Needed.Value.."/2)"
				if sign.Ingame.Needed.Value >= 2 then
					sign.Ingame.Current.Value = "Cash"
					sign.text.SurfaceGui.TextLabel.Text = "Need: 2500$"
					prompt.ActionText = "Insert 2500$"
                end
				elseif sign.Ingame.Current.Value == "Cash" then
					if game.Workspace.Cash.CashNumber.Value >= 2500 then
						game.Workspace.Cash.CashNumber.Value -= 2500
						ingame.Level.Value += 1
						sign.Ingame.Current.Value = "Soul"
						sign.Ingame.Needed = 4
						sign2.text.SurfaceGui.TextLabel.Text = "Farm Upgrader: Level "..ingame.Level.Value
						sign.text.SurfaceGui.TextLabel.Text = "Need 4 Soul Pieces (0/4)"
                       end
					elseif ingame.Level.Value == 2 then
						if sign.Ingame.Current.Value == "Soul" then
							local char = game.Workspace:FindFirstChild(plr.Name)
							if char:FindFirstChild("Soul Piece") then
								local piece = char:FindFirstChild("Soul Piece")
								piece:Destroy()
								sign.Ingame.Needed.Value += 1
								sign.text.SurfaceGui.TextLabel.Text = "Need: 4 Soul Pieces ("..sign.Ingame.Needed.Value.."/4)"
								if sign.Ingame.Needed.Value == 4 then
									sign.Ingame.Current.Value = "Cash"
									sign.text.SurfaceGui.TextLabel.Text = "Need: 5000$"
									prompt.ActionText = "Insert 5000$"
								end
							elseif sign.Ingame.Current.Value == "Cash" then
								if game.Workspace.Cash.CashNumber.Value >= 5000 then
									game.Workspace.Cash.CashNumber.Value -= 5000
									ingame.Level.Value += 1
									sign2.text.SurfaceGui.TextLabel.Text = "Farm Upgrader: Level "..ingame.Level.Value.." (MAX)"
									sign.text.SurfaceGui.TextLabel.Text = "Can't Upgrade Anymore"
							        prompt:Destroy()
						end
					end
				end
			end
		end
	end
end)

Im pretty sure its being met. I re-checked it a lot of times.

also is the string “cash” a number value?

The cash value in workspace is a number value.

Apparently, putting another end worked, also i missed .Value in line 25.