Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add a custom sound to play along with the animation?

Asked by 5 years ago

local Player = game.Players.LocalPlayer local Character = workspace:WaitForChild(Player.Name) local Humanoid = Character:WaitForChild('Humanoid')

local RunAnimation = Instance.new('Animation') RunAnimation.AnimationId = 'rbxassetid://3331343593' RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState) if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then Running = true Humanoid.WalkSpeed = 35 elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then Running = false if RAnimation.IsPlaying then RAnimation:Stop() end Humanoid.WalkSpeed = 16 end end

Humanoid.Running:connect(function(Speed) if Speed >= 16 and Running and not RAnimation.IsPlaying then RAnimation:Play() Humanoid.WalkSpeed = 35 elseif Speed >= 16 and not Running and RAnimation.IsPlaying then RAnimation:Stop() Humanoid.WalkSpeed = 16 elseif Speed < 16 and RAnimation.IsPlaying then RAnimation:Stop() Humanoid.WalkSpeed = 16 end end)

Humanoid.Changed:connect(function() if Humanoid.Jump and RAnimation.IsPlaying then RAnimation:Stop() end end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)

0
Please help, I am making a game on ROBLOX called Prince Jousting EnStriker 0 — 5y
0
Well im new to scripting, but do you have the sounds inside the script, like if you right click on the thing and click insert object, you should see an object called sound. fighterkirbyzx 102 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It is little easy all you have to do is add a sound to the animation and then say

RunAnimation.Sound:Play()--- change sound to the name of the song in the animation

and if you want it to play just for the 1 player just say

local Sound = RunAnimation.Sound --- change sound to the name of the song in the animation

Sound.Parent = game.Player.LocalPlayer.PlayerGui

Sound:Play()
Ad

Answer this question