Hey, Fellow Developers!
I am making a boba shop and need help with scripting the boba drinks and animating them.
I have made an animation and I have tried other scripts and they don’t work.
Thanks,
Soli
Developer of Boba Shop GG
Hey, Fellow Developers!
I am making a boba shop and need help with scripting the boba drinks and animating them.
I have made an animation and I have tried other scripts and they don’t work.
Thanks,
Soli
Developer of Boba Shop GG
Alright, So let’s get started. This should be quite simple. I haven’t really played any games like that but I assume you want the player to be able to consume them (with animations)? Please correct me if I am wrong. Once that is clarified I shall start.
Yes, this is right! Thank you!
Alright, So assuming that you’re drink is a tool, You could simply have this local script inside of it that will have the activated event connecting to it and then from there you could animate it and add a debounce. Basically something like this :
local drink = script.Parent -- this searches for an animation inside the drink, so make sure to create an animation inside of and
local db = 1 -- debounce time
local onDb = false -- debounce value
drink.Activated:Connect(function()
local drinkAnim = drink.DrinkAnimation
print("activated")
if onDb == false then
onDb = true
warn("Drinking The Juice")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() -- waits for the character to be loaded and puts it in a variable.
if char.Humanoid:FindFirstChild("Animator") then -- checking if animator is existent
local drinkAnimation = char.Humanoid.Animator:LoadAnimation(drinkAnim) -- loading animation
drinkAnimation:Play() -- playing animation
else
local a = Instance.new("Animator") -- making a new animator if it isn't existent
a.Parent = char.Humanoid -- parenting the animator to the character
local drinkAnimation = char.Animator:LoadAnimation(drinkAnim) -- loading animation
drinkAnimation:Play() -- playing animation
end
end
task.wait(db) -- waiting the amount of debounce
onDb = false -- setting the debounce to false so the player can use it again
end)
This should be what you’re tool looks like In the explorer :
Result :
Or of course, You could do it the Object Oriented Way (OOP). It is harder to learn but once you get it down it is fairly simple and way more efficient, There is more on OOP here :
Forgive me I am kind of rusty so I might have done some mistakes here and there, make sure to try it out and come back to me if anything is wrong. ( don’t forget to read the comments on the script, very important and will provide you an understanding of the script and how it works. This script will only play the animation, if you want to handle anything else please let me know.)
How do I make it work with multiple parts