How do I refer to these attributes?

  1. What do you want to achieve?
    I basically want to refer to the attributes in the image (Carni, herbi and omnivore) for a hunger system in my animal survival game. The eatables have bool values (Eatable → true/false) which works perfectly fine if u tick the box, it’s eatable and if not then it’s not. Now I want it, if you tick the box carnivore, the bool of the eatable thing “Grass” becomes false, so that the animal cannot eat it. If herbivore, the bool eatable for “Meat” becomes false. And for omnivore, both values are true for grass and meat.

  2. What is the issue?
    I kinda don’t know how I should comprehend it in a script so it actually works.

  3. What solutions have you tried so far?
    looked on the dev hub but was not able to find anything since this is a specific case.

That’s some code I tried but with no effect (I am not surprised)

local carnivore = false
local herbivore = false
local omnivore = false
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local meat = game.Workspace.Meat.Eatable
local grass = game.workspace.Grass.Eatable

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		if humanoid.Carnivore == true then
			
			meat = true and grass == false
			
		elseif humanoid.Herbivore == true then
			
			meat = false and grass == true
			
		elseif humanoid.Omnivore == true then
			
			meat = true and grass == true
		end
	end)
end)

The attributes, stored in the humanoid of the animal model:

1 Like

Attributes cannot be used by simply typing Instance.Attribute
In order to get the value of an attribute or check if it even exists use the :GetAttribute(AttributeName: string) function

In order to set the value of an attribute (or even create one using a script) use the :SetAttribute(AttributeName: string,Value: any) procedure

Example
Humanoid:SetAttribute("Omnivore",false)

2 Likes

Oh thank you! I’ll try right now and see what I can do!

You are also using and incorrectly. and is not used to set multiple values but instead as a logical operator.

meat = true and grass == false will not work, also a double equals == is used to check if a value is equal to X and a single equals = sets the value to X, as such even if and was useable in that context it would still not work. Instead use something such as meat,grass = true,false

2 Likes