Modificate route with a value

Hello, I’m trying to modify my animations according to a value that the character has, but I don’t know how to modify the route.
I’ve tried using a variable and converting it to a string, but it didn’t work.
Can you help me please? I tried this is the code:

	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local animator = humanoid.Animator
	local actualWeapon = character.Values.actualWeapon.value
	local combo = character:GetAttribute("Combo")
	if attacking then return end
	character:SetAttribute("Attacking", true)
	local animations = game.ReplicatedStorage.Anims.actualWeapon
	local animation = animator:LoadAnimation(animations[combo])

The output error is "actualWeapon is not a valid member of Folder “ReplicatedStorage.Anims”
I know why is the error but i dont know how to fix it

Based on the code you have provided, it looks like you are trying to access the actualWeapon field of the Anims folder in the ReplicatedStorage service. However, actualWeapon is not a valid member of the Folder class, which is the type of object that game.ReplicatedStorage.Anims is.

To fix the error, you will need to modify the code so that it accesses the correct object within the Anims folder. You could do this by specifying the exact path to the object you want to access, or by using a different method to retrieve the object.

For example, you could modify the code like this:

Copy code

local animations = game.ReplicatedStorage.Anims:FindFirstChild(actualWeapon)
if not animations then
	error("Could not find animation for weapon: " .. actualWeapon)
	local animation = animator:LoadAnimation(animations[combo])

This will try to find a child of the Anims folder with the same name as the actualWeapon variable, and then load and play the animation if it is found. If the child is not found, an error will be thrown.

Alternatively, you could use a different method to retrieve the animation object, such as a for loop or a try-catch block.

I generated this response with, let me know if you have any further questions and I’ll give the AI that. Note that sometimes the code it generates is wrong and some manual fixing has to be done. I haven’t tested this now but from my eye it looks correct.

1 Like

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