How much slower are value objects compared to variables

local loopingValueObject = enemyState.Looping

local function loop()
	if loopingValueObject.Value then return end
	loopingValueObject.Value = true
	while loopingValueObject.Value do
		print("Looping")
		wait()
	end
end

local function endLoop()
	if not loopingValueObject.Value then return end
	loopingValueObject.Value = false	
end

This is what I want to do when a certain value needs to be in a value object for clients to see, but I’m wondering if this going to have any performance issues

if it does then my solution is to use a variable and a value object

local loopingValueObject = enemyState.Looping
local looping = false

local function loop()
	if looping then return end
	looping = true
	loopingValueObject.Value = true
	while looping  do
		print("Looping")
		wait()
	end
end

local function endLoop()
	if not looping then return end
	looping = false
	loopingValueObject.Value = false	
end

but this version is more work than just using a value object

I know the performance will likely not matter for most cases, but I’m more worried about very vast loops as it would be checking the value a ton of times, instead of just comparing to a variable

You can test this with Studio’s Script Performance option.

Also, I recommend putting this in Code Review instead of Scripting Support, because the code is already functional, and you’re just looking for improvements.

Thanks didn’t know that existed

from what I’ve just seen, there doesn’t seem to be much of a difference between the two, which is a bit surprising to me

1 Like