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

The script worked fine before I add elseif statement, anything wrong?

Like the title says, the script worked fine before I added elseif (statistic.Value == statistic.Value+statistic.Value>=8) then statistic.Value = lastValue. What's wrong?

local xd = Instance.new("IntValue")
	xd.Name = "Level"
	xd.Parent = leaderstats
	xd.Value = 1
	local statistic = xd
	local lastValue = statistic.Value  
statistic:GetPropertyChangedSignal("Value"):connect(function()  
if (statistic.Value < lastValue) then
	statistic.Value = lastValue
elseif (statistic.Value == statistic.Value+statistic.Value>=8) then
	statistic.Value = lastValue
        return    
end
    lastValue = statistic.Value
end)

2 answers

elseif (statistic.Value == statistic.Value+statistic.Value>=8) then

It is because you can't have two operators in one conditional statement without adding "and" or "or". You have == (is equal to) and >= (is greater than or equal to). You would need to add "and" or "or" to use two operators in one statement.

To expand upon what Asceylos said, what you are doing is redundant.

All of the possible combinations except one that involves a bool value are incorrect (the bool value not working with the rest of your script anyway).

Checking if the value is equal to the value is pointless since it is guaranteed to be true every time.

Therefore meaning only one thing can work:

if statistic.Value >= 8 then

end

You did almost exactly the same thing right at the start of your if statement - so remember, programming is consistent. The syntax and requirements of conditions do not change if you are putting them somewhere else.


Hope I helped!

~TDP

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