Help with getting value from dictionary

I have a dictionary where each part corresponds to another part, so that I can get a parts corresponding part from the part. Here’s my script:

local doorToZoneTable = {
	bakery = bakeryZone,
	fantasy = fantasyZone,
	jungle = jungleZone,
	mars = marsZone,
	ocean = oceanZone,
	party = partyZone,
	space = spaceZone,
	tech = techZone

	door.CanCollide = true
	local targetZone = doorToZoneTable[door]
	local isWithinZone = targetZone:findLocalPlayer()
	if isWithinZone then
		local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
		local hrp = character:WaitForChild("HumanoidRootPart")
		hrp.Position =, door.CFrame.Position.Y, (door.CFrame.Position.Z + 5))

For some reason though, when I try to get the corresponding part, it won’t work. Why is this happening?

1 Like

I don’t know what you are sending via :FireClient(door) if it is a part then you need to use the part name like so. The issue is you need to use a string as your table’s key since that is how it was defined.

local targetZone = doorToZoneTable[door.Name]

Thanks. I just figured out what I was doing wrong was that all of the keys were objects so I needed to put them in square brackets like this:

[bakery] = bakeryZone
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.