Hey there fellow developers! Can you guys help me?
What do you want to achieve?
I want to add a reload animation to this script, I was following a tutorial just so you know.
What is the issue?
I’m not a very good scripter and I’m still learning. Anyways, I can’t add a Reload Animation to this script.
What solutions have you tried so far?
I tried trying to add one myself by following tutorials from other videos and inserting those scripts into the this script but I didn’t work.
--Variables
local gun = script.Parent
local gun_shot = gun.Handle['Pistol Shoot']
local empty_sound = gun.Handle["Dry Fire"]
local reload_sound = gun.Handle["Pistol Reload"]
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--MouseIcon
--Remote Event Setup
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
--Mouse Click Check
gun.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
remoteEvent:FireServer(gun.Handle.Position, mouse.Hit.p)
gun_shot:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
empty_sound:Play()
end
end)
end)
--R to Reload Check
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
gun.Ammo.Value = 0
reload_sound:Play()
reload_sound.Ended:Wait()
gun.Ammo.Value = 6
end
end
end
end)
local ReloadAnim -- at the top of the script where variables are
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character --[[ im assuming this is a localscript
if its not then dont do this]]
-- in the reload function
ReloadAnim = character:FindFirstChild("Humanoid"):LoadAnimation(gun.[name of your animation])
if ReloadAnim then ReloadAnim:Play() end
local tool = script.Parent
local humanoid
local animator
local reload: AnimationTrack -- typing : AnimationTrack in not necessary
tool.Equipped:Connect(function() -- set humanoid once the tool is equipped
humanoid = tool.Parent:FindFirstChild("Humanoid") -- define both user's humanoid and animator
animator = humanoid:WaitForChild("Animator")
reload = animator:LoadAnimation(reloadAnim) -- "reloadAnim" must be an Animation object.
end)
-- Place this anywhere in the 'reload' function.
reload:Play()
you are welcome but also, the post below mine’s code is more up-to-date as it uses the Animator object (something i never used or heard of before) so you should find out how you can use his code in the future