Hello, I made a flying script, but I want to add an animation in this script. I’ve never done this so don’t know how to add. I try in many ways but nothing works. Can anybody help?
LOCALSCRIPT
repeat wait() until game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local tor = char:WaitForChild("LowerTorso")
local mouse = player:GetMouse()
local de = false
mouse.KeyDown:Connect(function(key)
if key == "f" then
if de == false then
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://4516044669"
local play = hum:LoadAnimation(anim)
play:Play()
de = true
local bodyvel = Instance.new("BodyVelocity",tor)
bodyvel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
while de == true do
bodyvel.Velocity = mouse.Hit.LookVector * 50
wait()
end
end
if de == true then
de = false
tor:FindFirstChildOfClass("BodyVelocity"):Destroy()
end
end
end)
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://2510199791"
animation.Parent = script
local track = animator:LoadAnimation(animation)
track.Looped = true
local torso = character:WaitForChild("LowerTorso")
local mouse = player:GetMouse()
local toggle = false
userInput.InputBegan:Connect(function(key, processed)
if processed then return end
if key.KeyCode == Enum.KeyCode.F then
toggle = not toggle
if toggle then
track:Play()
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Parent = torso
while true do
task.wait()
if toggle then
bodyVelocity.Velocity = mouse.Hit.LookVector * 50
else
bodyVelocity:Destroy()
break
end
end
end
end
end)
I tested using the “RThro Swim” animation and it worked.
Yes, this script WORKS , I only add animation disabling via track:Stop (), but where can I find a flying animation that would work too. I can’t find any in the roblox library.