Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Way to play an animation when a BoolValue's Value = true?

I tried this script, but it wasn't working. Please Help!

if script.Parent.PlayOverhead.Value == true then
	game.Players.LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
:LoadAnimation(script.Parent.OverheadAnim2)
	game.Players.LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
:PlayAnimation(script.Parent.OverheadAnim2)
end

Thanks!

1 comment

0

AnimationName:Play().

1 answer

First of all the script only runs once in the whole entire time you play the game.

For the script to check if a value is true, you want the script to load the animations only when the boolean is changed.

So we should make a changed event.

script.Parent.PlayOverhead.Changed:connect(function()
if script.Parent.PlayOverhead.Value == true then
    game.Players.LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
:LoadAnimation(script.Parent.OverheadAnim2)
    game.Players.LocalPlayer:WaitForChild("Character"):WaitForChild("Humanoid")
:PlayAnimation(script.Parent.OverheadAnim2)
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.