Attributes vs Tables

If I had a combat game and needed to store data such as if the player is blocking or not, which of these would be the better way of doing things?

local Players = game:GetService('Players')

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		Character:SetAttribute('Blocking', false)
		Character:SetAttribute('Disabled', false)
		Character:SetAttribute('Attacking', false)
		
	end)
end)

or

local Players = game:GetService('Players')

local Table = {}

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		Table[Character] = {
			['Blocking'] = false,
			['Disabled'] = false,
			['Attacking'] = false
		}
		
	end)
	
	Player.CharacterRemoving:Connect(function(Character)
		Table[Character] = nil
	end)
end)

return Table

The first one is in a server script and the second one is in a module script.

Edit: I forgot to mention that I intend to store more data like damage reduction and damage multiplier values.

3 Likes

A dictionary would be faster to access for the script so therefore better, but it mostly comes to personal preference if you aren’t checking the data too often.

Thank you for your reply, may I ask why you said “if you aren’t checking the data too often.” Does checking attributes use a lot of resources or something?

No, it uses very minimal resources, but tables use even less.

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