Parameters are going insane!

I have a RemoteEvent that needs to transport table data between server and client, however, something really went wrong at some point.
Firstly I wrote a function to check if something is there.

function check(obj)
	if obj then
		return "true" or true
	else
		return "false" or true
	end
end

Now, I checked with a print(). It did print.

print(string.format("Ahh, computer program activated. Parameters: %s, %s, %s. Does the crap work?",Player.Name,check(UIData),check(VirtData)))
-- octav20071, false, true

But, when I did these lines:

if VirtData then
		print("Functions and codes and values and madness")
	else
		print("Something went really wrong!")
	end
end

And guess what printed. Anyway, why is this happening? Unless this is a backend bug, I am just going insane.

Why don’t you just return either true or false?

function check(obj)
    if obj then
        return true
    else
        return false
    end
end

This might sound dumb but what is VirtData?

If its value is “false” then this will not check correctly.

Instead of
if VirtData then
You could use
if VirtData ~= nil then

If this doesn’t work, then we’re gonna need to to explain what you’re doing here.

They both work the same way


If the variable holds a “false” then it will be interpreted as a false condition, and give the same result as if there was nothing in the variable.

“false” always exists so check() will never return false. It will return “false”, “false” is a string so it is true. Just use normal statements

I thought you meant the bool value false not a string that is “false” nevermind

There’s no possibility to even remotely go about helping you with us not having knowledge of the variable “VirtData”.

Please, explain what VirtData is and how you’re assigning the values to the variable.

And this can get over-simplified to just returning the condition:

function check(obj)
	return (obj == true)
end

Also the error may exist due to the fact that, if obj is nil or false, it returns "false" instead of false and because lua conditions think strings are true the if statements run, example:

local value = "false"
local value2 = false 

if value then
	print("I will run")
end
if value2 then
	print("I will not run")
end

‘else’ can return false, and it can also return nil.

You can test this by printing obj before the conditional statement and changing the value being passed to either false or nil, and it will return the latter. I’d recommend specifically looking for false or nil in your conditional statement.

VirtData is a table.
@SamsAltAcc0unt

Is the table referenced? Do you edit the referenced table in that case before printing again, or perhaps a coroutine? Try to see if a deep copy is necessary

At first the table is referenced like this: (Client)

local VirtData = {
	Scanner1 = nil,
	Scanner2 = nil,
	Scanner3 = nil,
	Scanner4 = nil,
	ScannerDelay = nil,
}

Upon advancing onto a specific program, the variables change. From Scanner1 to Scanner4, boolean values will be applied. The ScannerDelay is supposed to be an int, and based on ​my sanity checks, it will always be.
Here, I use an if statement and eventually fire the RemoteEvent:

if not ScannersAvailable then
	print("No Scanner is available")
	--GaMe:print("No Scanner is available")
else
	for Index, Value in pairs(VirtData) do
		print(tostring(Value).." at "..Index)
	end
	print("Firing the remote from "..Player.Name)
	RemoteEvent:FireServer(nil,VirtData)
end

Which results in:

false at Scanner3
false at Scanner2
10 at ScannerDelay
true at Scanner1
false at Scanner4

Discovered that there is a task.wait() in the script, I will try using coroutines.

Nah, just because a bool couldn’t be converted to a string.


Anyway, @SharpSerious managed to fix my problem using 1 word, which is

but still, thanks for all your help!