How to make a gui textbox activate a animation to play on a dummy

Hello, I would like to achieve the proper working function for a script I have been trying to do.

The issue is I have been trying many ways to resolve a proper way to use some of the code I have done but they all ended up failing in the process. I have tried ways to achieve the result with tables, modules and events but non seem to work properly.

Basically I would like when a GUI text-box is pressed it will activate a animation to play on a specific dummy. I would really like if anybody could help me with this issue. I have been trying a lot to do it But i dont think I can properly make it correctly so if anybody has a solution or info please tell me. -P.s This is very important for my game.

1 Like

Don’t you mean the text button?

This is my way to activate for the to play the animation.

local textButton = script.Parent
local npc = workspace.npc -- path to npc
local animation = npc.Animation -- path to animation property

textButton.MouseButton1Click:Connect(function()
	local anim = npc.Humanoid:LoadAnimation(animation)
	anim:Play()
end)

(This is clientside, which means player in server or other clients can’t see, but tell me if you want it serverside)

2 Likes

Thank you for this I believe this will work perfectly but also I do not have an animation property I only have a script that runs the animation inside of the dummy so maybe any help for that? Like do I need to add an animation track to it or something

My bad, I meant the instance, not property. (Animation track)

1 Like

So do I refer to the script? Because this is the script I have in it: local Character = script.Parent
local animation = Instance.new(‘Animation’)
local track = nil
animation.AnimationId = “rbxassetid://6867024177”
track = Character.Humanoid:LoadAnimation(animation)
track:Play()

You don’t have to necessarily change the animation if it has already been set on studio.

1 Like

I just need a path to the animation but Idk if i refference the script because the script is the only thing in the dummy no animation tracks or scripts besides it

It still will work so you don’t need to bother with the script in the dummy.

(I don’t know what script are you mentioning in the dummy)

1 Like

Ok I removed the script in the dummy, So in local animation = npc.Animation – path to animation property What would I put? The text button is in starter gui and the dummy is in workspace
the local script u gave I put in the text button and the only thing I do not get is:
local animation = npc.Animation – path to animation property (I dont know what to put there)

Sorry for making you confused, you don’t need an animation property.

It’d look like this.

local textButton = script.Parent
local npc = workspace.npc
local animation = npc.Animation

textButton.MouseButton1Click:Connect(function()
	local anim = npc.Humanoid:LoadAnimation(animation)
	anim:Play()
end)
1 Like

Thank you, I will test to see if it works!

Ok so it doesnt play an animation

Maybe because I didnt put one or something?

did you path it to the animation?

1 Like

How would I do that I dont have any animation inside the dummy or ur talking about saved anims?

You need to run the code on the server, only the player’s animation replicate but NPC’s animation don’t replicate. Fire a Remote event to the server and then play the animation.

Do you want something like this? I made this a while ago, tell me if you want me to send the script.

2 Likes

Yes That is exactly what I need

ah ok. sorry for the late reply i forgot about this. heres the script (it should be a script under the gui button):

script.Parent.MouseButton1Click:Connect(function()
	local humanoid = game.Workspace.Dummy.Humanoid --change the path if ur dummy is named smth else
	local animation = Instance.new("Animation")
	animation.AnimationId = "http://www.roblox.com/asset/?id=your animation id"
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()
end)
9 Likes