I understand this title is not very helpful as-is. I hope from what I've shown you can help understand what my error is and maybe help me out.
I have three buttons in a GUI which is given by a morph. Only one button is visible at a time, and the first two buttons play animations. These two are looped animations, and the final is a .1 second, non-looped, no movement animation in an attempt to cease the previous animation. The first two are idle-priority, and the final is action, so the priority has nothing to do with here.
Each AnimID is correct and I've checked thrice over. First ID Second ID Third ID
Inside the LocalScript I set up what button activates what animation using this code:
wait(1)
local frame=script.Parent
local user=game.Players.LocalPlayer
repeat wait() until user.Character local char=user.Character
local humanoid=char:WaitForChild("Humanoid")
local anim
function playanim(id)
if char~=nil and humanoid~=nil then
local id="rbxassetid://"..tostring(id)
local oldanim=char:FindFirstChild("LocalAnimation")
if anim~=nil then
anim:Stop()
end
if oldanim~=nil then
if oldanim.AnimationId==id then
oldanim:Destroy()
return
end
oldanim:Destroy()
end
local animation=Instance.new("Animation",char)
animation.Name="LocalAnimation"
animation.AnimationId=id
anim=humanoid:LoadAnimation(animation)
anim:Play()
end
end
local b1=frame.SP
b1.MouseButton1Down:connect(
function()
playanim(b1.AnimID.Value)
end)
local b2=frame.SP2
b2.MouseButton1Down:connect(
function()
playanim(b2.AnimID.Value)
wait(3)
anim:Stop()
end)
local b3=frame.BBK
b3.MouseButton1Down:connect(
function()
playanim(b3.AnimID.Value)
end)
local b4=frame.BBK2
b4.MouseButton1Down:connect(
function()
playanim(b4.AnimID.Value)
end)
local b5=frame.SP3
b5.MouseButton1Down:connect(
function()
playanim(b5.AnimID.Value)
anim:Stop()
end)
local b6=frame.BBK3
b6.MouseButton1Down:connect(
function()
playanim(b6.AnimID.Value)
end)
Pay no mind to SP, the problem is with the BBK buttons. On button press one, it plays the first animation and executes the following script:
local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Character
local frame = script.Parent.Parent
local button = script.Parent
function onClick(mouse)
wait(.5)
player.Chest.Middle.A.BBKC.Enabled = true
button.Visible = false
frame.BBK2.Visible = true
end
script.Parent.MouseButton1Down:connect(onClick)
The second button is then pressed, executing this script:
local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Character
local frame = script.Parent.Parent
local button = script.Parent
function onClick(mouse)
wait(.5)
player.Chest.Middle.A.BBKC.Enabled = false
player.Chest.Middle.B.BBK.Enabled = true
button.Visible = false
frame.BBK3.Visible = true
end
script.Parent.MouseButton1Down:connect(onClick)
Both of these scripts work fine, and the third script on button three is executed:
local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Character
local frame = script.Parent.Parent
local button = script.Parent
function onClick(mouse)
wait(.5)
player.Chest.Middle.B.BBK.Enabled = false
button.Visible = false
frame.BBK.Visible = true
end
script.Parent.MouseButton1Down:connect(onClick)
This script works fine, however the animation from button two will not stop. Can anyone help me make the animation stop on the third button press?
