Script variable keeps resetting for seemingly no reason

For some reason, theres some issue in this chunk of code thats causing the value to reset for seemingly no reason. I know its an issue within this chunk of code as the issue still persists even when completely isolated

Mood = 1
CurrentComment = "%2Test"
local First = string.sub(CurrentComment,0,1)
if First == "%" then
	local Mood = tonumber(string.sub(CurrentComment,2,2))
	print(Mood.. " Check A")
	if Mood == nil then
		--Placeholder for other code, its not the cause of this behavior
	else
		CurrentComment = string.sub(CurrentComment,3,-1) -- This line is also not the cause
		Mood = (2*Mood)-1
		print(Mood.. " Check B")
	end
end
print(Mood.." Check C")

Check A = 2
Check B = 3
Check C = 1/Whatever the default mood is

1 Like

What is the expected behavior?

1 Like

Check B and C have different values despite nothing changing it, Somehow the value gets reset after check B

1 Like

Change this to
Mood = tonumber(string.sub(CurrentComment,2,2))

1 Like

you should put this in #help-and-feedback:scripting-support

1 Like

oh yeah mb, its been a while since ive posted on here

1 Like

Ty, i dont know how i missed that

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.