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

Can we compare Enums with strings or another way?

I did a sistematic combat system, it iterares all over looking for the attack by the specified key. Turns out i can't compare Enums with strings or their repective values from the Wiki. If i can't compare it this way then i would have to define the event for each attack and that would be overkill.

plyInput.InputBegan:connect(function(input, validInput)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local currentPlayerAbilities = plyAbilities:GetChildren()
		for i = 1, #currentPlayerAbilities do
			print(currentPlayerAbilities[i].Name)
			print(currentPlayerAbilities[i].Value)
			if currentPlayerAbilities[i].Value == input.KeyCode then
				local currentGameAbilities = Abilities:GetChildren()
				for i = 1, #currentGameAbilities do
					if currentGameAbilities[i].Key.Value == input.KeyCode then
						local chosenAbility = currentGameAbilities[i]
						local output = chosenAbility.BaseDamage.Value + plyStats.Strenght.Value
						local attackAnimation = plyChar.Humanoid:LoadAnimation(chosenAbility.Animation)
						attackAnimation:Play()
						AttackingState = true
					end
				end
			end
		end
	end
end)

1 answer

✓ Accepted answer

Enum value's have a Name property you can query to compare to strings i.e. print("Slate" == Enum.Material.Slate.Name)

In your case, you would use currentGameAbilities[i].Key.Value == input.KeyCode.Name

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