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.
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.
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
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.