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

How do I use variables more effectively?

Hello. I got many variables in my script, like this

local 1qq
local 2qq
local 3qq
local 4qq
--and so on

players will be in different position. if they are in position 4, i want use 4qq only But surely I can't concatenate it so its like

Map.Number.Value.."qq"

is there any way to use these variables more effectively?

1 comment

0

well you can use tables

1 answer

✓ Accepted answer

In your case you can use tables and pairs loop like Kanye West said.

local positions = {
	["1qq"] = Vector3.new(0, 2, 5),
	["2qq"] = Vector3.new(50, 100, 0),
	["3qq"] = Vector3.new(0_123, 0.123123, 0),
	-- Add as many positions as you need
}

for positionName, vector in pairs(positions) do
	if player.Position == vector then
		print("Player is in this spot:", positionName)
	end
end

This loops through all the positions in the table and checks if player is in the current position. PositionName is the variable name (So "1qq" or "3qq"...) and vector is the position.

This might be inefficient way of doing it as if player position is only 0.1 stud off your spot then it will not work, for that you could use regions.

2 comments

1

0.1 stud off , use Vector3:FuzzyEq then Returns true if the other Vector3 falls within the epsilon radius of this Vector3.

0

that makes sense, thank you so much

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