This Roblox development video shows you how to create a drink animation and add it to a "potion", place everything into a tool so you can pick it up, press the F key, and drink.
------------- Drink script (local script) --------
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local anim = script.Parent.DrinkAnim
local track = animator:LoadAnimation(anim)
local uis = game:GetService("UserInputService")
local drinkKey = Enum.KeyCode.F
local isFinished = true
local sound = script.Parent.Slurp
-- only drink when equipped
local isEquipped = false
local tool = script.Parent
local function playAnim(input)
if isFinished and input.KeyCode == drinkKey and isEquipped then
isFinished = false
track:Play()
wait(track.Length/4)
sound:Play()
track.Stopped:Wait()
isFinished = true
end
end
uis.InputBegan:Connect(playAnim)
-- Not in video, but needed or player will drink even if it's in his backpack
tool.Equipped:Connect(function()
isEquipped = true
end)
tool.Unequipped:Connect(function()
isEquipped = false
end)