Struggling with in pairs and dictonarys

am doing something wrong

					for _, cancel in pairs(MovementDictionary) do
					if cancel.Pose == Pose then
						print(cancel.Pose)

Pose is a variable and only has one value at a time, like “Idle”
it should only be ran once because there’s only one value for cancel.pose
but it runs and prints two things?

21:57:06.481  Sprinting  -  Client - Controlling:103
  21:57:06.481  Crouching  -  Client - Controlling:103
1 Like

How does the table look like you are using in the for loop?

2 Likes

Youve probably got 2 things in the table and its printing things for both

1 Like

its a dictonary with two tables inside and both has [“Pose”] inside, am trying to find if the [“Pose”] matches the current pose in the script

1 Like

Are you sure there’s only one value in the dictionary?

1 Like

theres a Pose variable in the script which is just the current pose that the characters in
its just this

local Pose = "Crouching"

the dictonary is like this

local MovementDictionary = {
	["Sprinting"] = {
["Pose"]  = "Sprinting"
}

["Crouching"] = {
["Pose"] = "Crouching"
}}

am trying to loop through the table to see if the Pose varaible matches with a value from the Dictonary
like this

for _, cancel in pairs(MovementDictionary) do
					if cancel.Pose == Pose then
						print(cancel.Pose)

for example it runs twice and calls sprinting and crouching, am trying to make it only call the crouching

1 Like

You can just do this:

for _, cancel in pairs(MovementDictionary.Crouching) do
					if cancel.Pose == Pose then
						print(cancel.Pose)

its not gonna be crouching everytime though
It has multiple functions like sprinting and crouching so it need something that works for both

What happens when you print the Pose variable. It might be being changed from somewhere

  22:38:45.559  Sprinting  -  Client - Controlling:104
  22:38:45.560  Crouching  -  Client - Controlling:104

Am just trying to find a way to check if the boolean Pose is the same as a value inside a dictonary

You need to check the index, not the value

for index, cancel in pairs(MovementDictionary) do
					if Pose == index then
						print(cancel.Pose)
2 Likes

i think its my coding because this doesnt work either
ill try more tomorrow, thx For helping

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