How to grab the difference between two different IntValue numbers?

So I have two IntValues for two team’s soccer goals, I’m trying to just grab the number value from the two IntValues in a Script in the ServerScriptService. I’m using IntValues so you can add (value = value + 1) numbers.

Here’s the bit of code that I have on the server-side “Framework/Engine” script of the game located in the ServerScriptService:

		local GS = script.greenscore.Value
		local OS = script.orangescore.Value
		
		if #GS<#OS then
			for i,v in pairs(game.Teams["Orange"]:GetPlayers()) do
				v.leaderstats.XP.Value = v.leaderstats.XP.Value + 5
			end
		elseif #OS<#GS then
			for i,v in pairs(game.Teams["Green"]:GetPlayers()) do
				v.leaderstats.XP.Value = v.leaderstats.XP.Value + 5
			end
		end

This doesn’t work though, even though I think I’m supposed to be using “for i” values or something. I just need help.

Thanks!

2 Likes

image

Probably because you’re using an operator needlessly on a value. Would help if you debugged this yourself by adding prints or checking the console first before asking what the issue is.

6 Likes

Oh wow I’m dumb, I didn’t think you could just grab the values like that so simply. Thanks, I’ll have to do some more debugging with prints and stuff more.

There would of been an error in the output.

It’s not that you’re dumb, you just didn’t know.

I assume that you’re using an IntValue object for scores. Since the value property of IntValues is a number (going off of user data types granted from the type() function), indexing its value returns a number. You can index either the object or the property.

local variable = IntValue.Value

Assuming the value of IntValue in the above is 50, it’d look like this:

local variable = 50

Ideally you’d want to use # when determining the length of something, such as a table (how many entries there are) or a string (alternatively, you can use the standardised library string - string.len(string) and string:len() are the same as putting # before the string). When you’re working with a number though, there’s no need to append the len (#) operator.

4 Likes