What's wrong with my script?

I’m making a codes and spins system, when the player writes “betacode” in the text box, he receives 2000 spins, however, I’m receiving this error when typing the code:

“attempt to perform arithmetic (add) on nil and number”

Here is my code with some more useful explanations:

 spinsValue = 5 --this is the initial spins value

print ("spins: " .. spinsValue) --[[   here I know that the spins value 
is not nil because it prints "spins: 5"   ]]--

script.Parent.FocusLost:connect(
	function(enterPressed)
		if enterPressed then
			print(script.Parent.Text) 
			local code = (script.Parent.Text)
			
			if code == "betacode" then --"betacode" is the code that needs to be entered to earn 2000 spins.
				
				_G. spinsValue = _G. spinsValue + 2000 --here is the error
				
				
 
				
			end
			
		end
	end
)


 if spinsValue >= 2000 then 
	print ("spins: 2000")
end
1 Like

I don’t see the purpose of .G there.

2 Likes

When I try without _G. nothing happens

Because the check only runs once.

2 Likes

So for it to work I need to redo the script?

1 Like

If you print the spins after you add 2000 it should show 2005

local spinsValue = 5 --this is the initial spins value

print("spins: " .. spinsValue)

script.Parent.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		local code = script.Parent.Text

		if code == "betacode" then
			spinsValue = spinsValue + 2000
			print("spins: " .. spinsValue)
		end
	end
end)
2 Likes