Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Which is better in my current condition? Click to find out

I have been trying to add a value where it will show if a slot is taken or not

What should I use? I also need to know where to put the values. Lighting? ReplicatedStorage? What suits it best?

BoolValue or StringValue?

If I chose BoolValue then I won't know how to use it

Something like this;

local slot1value = Lighting:WaitForChild("TakenValue1")

and then I would be able to either set it true or false

If I chose StringValue then

Something like this;

local takenvalue.Value = Lighting:WaitForChild("TakenValue1")

The difference is I can change the StringValue to Taken or Free but for the BoolValue I would either set it True or False, Which is better? Where should I put the value? Please answer.

1 answer

✓ Accepted answer

tl;dr Use a BoolValue stored in ServerStorage.

Explanation:

A BoolValue would take up less space than a StringValue, since boolean is just a single bit set to 0 or 1 (simplifying here) but strings are several bytes (8 bits) long.

More importantly, the code I feel would be cleaner. If you set your BoolValue to the variable "takenValue", your code to check if it was taken would be:

if (takenValue.Value) then
	-- Is taken
else
	-- Is not taken
end

While if you used a string value it would be readable, but a little unnecessary:

if (takenValue.Value:lower() == "taken") then
	-- Is taken
else -- and this catches ALL strings that aren't "taken"
	-- Is not taken
end

Although in my opinion the best way to go would be to not use Objects at all for data storage, and instead use script variables, something like the following:

local isTaken = {false, true, false} -- 1, 2, and 3 in that order (2 is taken, the others aren't)

if (isTaken[1]) then
	print("1 is taken!")
else
	print("1 is free!")
end

-- Outputs
--> 1 is free!

Isn't that nicer?

3 comments

0

Would it work if I just said something like "If Taken == true then"?

0

Oh well, I will try it anyway

0

It depends what 'Taken' is. If 'Taken' is your BoolObject, then "if Taken.Value then" and "if Taken.Value == true then" are equivalent.

This discussion is preserved as it was. New answers, comments, and votes are closed.