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

Trouble with tool, containing animation and sound, how do I make this work?

So, I'm trying to make a tool with an animation. (this is my first time scripting). So far I've made the animation on click work, but I'm having two problems.

First problem is that currently if you spamclick it keeps replaying the animation with no delay, and I can't seem to fix this.

Second problem is that I'm trying to make a sound play with the animation as I click my mouse, but I can't make this work either.

I hope someone will be able to help me :)

(Here's my script so far)

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()

game.Players.StarterPack.Icecream.Activated:Connect(function()
   game.Players.StarterPack.Icecream.Handle.Lick:Play()
end)   


animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
   
   animation:Play()
    end)
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)

2 comments

0

Also, feel free to ask me if you have anymore questions!

0

I answered it :D

1 answer

✓ Accepted answer

The script looks pretty good for your first time scripting aside from a few errors. First, tools are stored inside a player's backpack. If an item is inside a player's backpack, it will show up in their inventory, if the item is equipped by the player, it will be in their character(in the workspace). The item is not stored in the starterpack anymore(this is why the sound did not work). Since the script will always be inside the tool no matter where it is, u can use script.Parent to find parts of the tool This script is the fixed version of the script:

script.Parent.Equipped:Connect(function(Mouse)
	local haslicked = false --this is our debounce to fix the spam problem
	 local icecream = script.Parent -- PUT AS MANY PARENTS AS NEEDED TO GET TO THE ICECREAM TOOL
	icecream.Activated:Connect(function licked)
	icecream.Handle.Lick:Play() 
	 
	local animation = 	game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
	 if haslicked == false then	--player can only play the animation when haslicked is false 
	 	 haslicked = true	--they can play the animation since it is true
		animation:Play()
		wait()
		haslicked = false-- now they can play it again instead of being able to spam
	       
		end
	end)
	end)
	 
	script.Parent.Unequipped:Connect(function()
	        animation:Stop()
	end)

If this script does not work then you may have to change the priority of the animation higher.

6 comments

0

If this is not the correct answer someone please correct me

0

Thank you so much for you help and feedback! Altough I had to change up a few minor things it works perfectly. So again, thank you! :D

0

Although, now I seem to have the problem that you can just spam the lick sound.

0

u can probably add a wait() afterwards to prevent that

0

Still doesn't seem to work for me

0

Sorry, I didn't explain it in a lot of detail, u can put a wait(1) after the Lick:Play(), if that doesn't work put it in before

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