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

Emote button works, but you can't use it again?

Basically, i have emote buttons. It works, the music works. The emote ends when you move, but it doesn't work twice. If you click, emotes dont work again.

Heres the script:

local emote = false
local name = ''
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=nil"
local animTrack = nil
local canPlay = true
local audio = false

for i,v in pairs(script.Parent.EmotesTab:GetChildren()) do
	if v:IsA("ImageButton") then
		v.MouseButton1Down:connect(function()
			animation.AnimationId = ("http://www.roblox.com/Asset?ID="..v.Name)
		if canPlay then
			local player = game.Players.LocalPlayer.Character
			canPlay = false
			animTrack = player.Humanoid:LoadAnimation(animation) 
			animTrack.KeyframeReached:connect(function(keyframeName)
				if keyframeName == "ElectrocuteEnd" then
					canPlay = true
			end
		end)	
		animTrack:Play()
		local pos = game.Players.LocalPlayer.Character.UpperTorso.Position
		if v:FindFirstChild("Audio") ~= nil then
			v.Audio:Play()
			audio = true
		end
		game.Players.LocalPlayer.Character.Humanoid.Running:Connect(function()
			animTrack:Stop()
			if audio == true then
				v.Audio:Stop()
			end
			
		end)
end
end)
end
end

Any help would be appreciated! Thanks.

2 comments

0

make a loop

0

where

1 answer

It's possible that the "ElectrocuteEnd" keyframe is never reached (keyframe name mis-match or non-existant?). Add a print statement before line 18 which prints out keyframeName to see which keyframes are being reached.

If the "ElectrocuteEnd" keyframe is never reached, your debounce (canPlay) will never reset.

3 comments

0

Tried that, it prints alot of different keyframes. https://gyazo.com/08b6bf1f873a638088c75a75eefe5512

0

Also, if it helps the animation is looped.

0

Yes, but none of those keyframes are named "ElectrocuteEnd"! That's the problem.

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