Pause all NPC animation with button gui

so im trying to make a script where the 1-3 Humanoids (they’re inside the “CirnoDay22” folder) would be all paused if i pressed “Settings”
i tried doing some scripting, but its abit tedious to paste to all 3 of em, so maybe doing an event?

local anim = script.Animation
local human = script.Parent.Humanoid
local move = human:LoadAnimation(anim)

move:Play()
game.StarterGui.Settings.Settings.MouseButton1Click:Connect(function()
move:AdjustSpeed(0)
end)

the animation works fine, but the pause didnt worked (even if i already pressed the button)

Because StarterGui stuff is copied to PlayerGui for players, so the player doesn’t see the button in StarterGui (You can’t detect him). I don’t know where you have the script but if in StarterGui you will have to use the script.Parent… until you get there.

the scripts locations (they contain the same codes, just different locations) are inside the models (pointed by the red hierarchies), button GUI is pointed with a red arrow

the GUI’s hierarchy (the red underline is the “Settings” button)
Screenshot_73

Because it’s an animation, you can just stop it, or pause it.

Use move:Stop(). And add a boolean value that toggles everytime you hit that settings button. If it’s true. Play the animation, if it’s false, stop the animation. By using boolean = not boolean.

Create a local script in the StarterGui (modify the path for the button). All animations will be named the same (those at startup). Everything is in local script so when the player joins the animation always starts playing from the beginning. The script will look something like this:

--Gui
local Button = script.Parent --> your path to button

--Workspace
local NPCS = workspace:WaitForChild("CirnoDay22")

--Value
local Pause = false

--Player Connect
for _,NPC in pairs(NPCS:GetChildren()) do
	local Human = NPC:FindFirstChild("Humanoid")
	if Human then
		local Move = Human:LoadAnimation(Human.StartDance) --> instead "StartDance" write your animation name
		Move.Looped = true
		Move:Play()    
	end
end

--MouseClick
Button.MouseButton1Up:Connect(function()
	Pause = not Pause
	for _,NPC in pairs(NPCS:GetChildren()) do
		local Human = NPC:FindFirstChild("Humanoid")
		if Human then
			for _, Move in pairs(Human:GetPlayingAnimationTracks()) do
				if Move.Name == "StartDance" then --> instead "StartDance" write your animation name
					if Pause == true then
						Move:AdjustSpeed(0)
					else
						Move:AdjustSpeed(1)
					end
				end
			end
		end
	end	
end)

this works! but is there a way to make them unpaused if i reclick the button?

Thank you! i completely forgot about using values :sweat_smile:
i dont know if im allowed to ask again but can this works for the cframe on the workspace? (example is on my screenshot) and since the cframe’s model can be changed on the settings button, it will obviously change name. so each name have to be put on a table
(i know we can use a in pairs, but im pretty new to it so im kinda stuck)

i hope this makes sense because i cant think of any words to describe it, and sorry if this bothers you!

okay so, in my first post ive putted some red pencil to indicate which are which and one of it is written cframe (parented to a workspace), its basicly a mesh with some cframes on it
Screenshot_80
the Drop and Squish ones are position and size, im pretty sure ive tried combining all of these three into one but only Rotat worked (which isnt a cframe).

Screenshot_98
these are the model names i just mentioned, ive asked a question previously and they use an in pairs (which im pretty new to) and tabled all of these names

and thank you for helping me! i extremely appreciate the time you took to help ^^!

1 Like