I have ,on the Developer Hub, looked for solutions but haven’t found any
local player
local character
local function switchanimID(animlocation,anim,id)
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:Wait()
character:FindFirstChild("Animate").animlocation.anim=id
end
I cannot figure out where the function’s problem is.
You are not specific on what you want the Path to find, Animlocation.Anim=id doesnt exist inside Animate, nor is it specified (Assuming), just specify which animation you want to change
“animlocation” is the string value that the animation object is in and anim is the animation object itself. I’m trying to find the path to the “animationID” property. Here is an image highlighting what I am talking about:
I’m not specifically pathing it to idle, I’m trying to make a function that can change any animation I set it to like walking or jumping animations. I’m not trying to change the animation when they reach a point, just the animations in the script. Also player and character were specified when I put
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:Wait()
Just copy the script from the Player while testing and edit its animations from there, not really a point in doing that unless changing the animations at a certain point.
What I want to do is create a function which can alter the animations from a tool and to do that I need to specify where each animation is using the parameters. For example if I wanted to swith the walking animation I would put:
switchanimID(walk,WalkAnim,"rbxassetid://[animation]")
--walk is the value
--WalkAnim is the Animation object
-- and the ID is the animation id
I’d like to be proven wrong by someone who knows more about Lua than I do, but I think what you’re trying to do (dynamically access a class or object’s property using a variable string) is impossible.
Figure out what doing this ‘the hard way’ looks like, and just do that.
This is right, you can’t directly access member properties of a class. Methods to do this are provided by interfaces only, i.e. functions, they internally expose the member properties to written changes provided by the function input parameters.