Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Simple If Statement messed up the next If statement, how do I fix this?

I have a function that basically turns ore into metal or raw meat into cooked meat. Both if Statements work independently, but with the first one in the function, when It is run on something that is "raw meat" (aka not an ore) the if statement recognizes that ore is nil and the script breaks. What I want it to do is recognize the ore is nil and then go on to the next If statement. Should be an easy fix I just must be missing something. Thanks guys! (I originally had just two separate if statements and no elseif, but then i tried the else if and neither work.

function heatUp(part)
	local heat = part.Heat
	local newName = heat.NewName.Value
	local newColor = heat.NewColor.Value
	local newRef = heat.NewRef.Value
	local newTrans = heat.NewTrans.Value
	local newOther = heat.NewOther:GetChildren()[1]

	part.Name = newName
	part.BrickColor = newColor
	part.Reflectance = newRef
	part.Transparency = newTrans
	
	if part.Ore.Value ~= nil then
		part.Mesh:remove()
		part.Size = Vector3.new(1, .6, 2)
		part.Material = ("Metal")
		else if
	
		part.Heat.Value ~= nil then
		part.Heat.NewOther.Edible.Parent = part
		part.Heat:remove()
		end
	end

2 answers

Your problem is that you wrote

else if

Instead of

elseif

2 comments

0

Common mistake, I've done it while making a slot machine

0

If you use elseif your code will be neater

The problem lays in your if statement. You use else if instead of elseif, wich would mean it requires an end for every new if.

What you're basicly doing is:

function stuff(args)

	if Statement then
		-- stuff
	else 
		if OtherStatement then
			-- stuff
		end
	end

--see the problem here? Not enough ends.

The easy way to solve this:

You gotta change your else if into elseif, because it'd require a few extra ends otherwise. That's all.

Example:

function stuff(args)

	if Statement then
		-- stuff
	elseif OtherStatement then
		-- stuff
	end
end

1 comment

0

For some reason I'm still getting the error "Ore is not a valid member of part" why would that matter if there's an elseif statement?

This discussion is preserved as it was. New answers, comments, and votes are closed.