Animation will not play

I made a module script for using weapons but no matter what I try, the animation won’t play, I have permissions for it and there are no errors in the output. Also, I am pretty sure there are no other animations playing and the animation controller is there

local rep = game:GetService("ReplicatedStorage")
local remotes = rep:WaitForChild("RemoteEvents")
local damageEffect = remotes:WaitForChild("DamageEffect")
local misc= rep:WaitForChild("Misc")
local hitbox = misc:WaitForChild("Hitbox")

local Melee = {}

function Melee.Attack(plr,weapon)
	local char = plr.Character
	if not char then return end
	local hum = char:FindFirstChild("Humanoid")
	if not hum then return end
	local track = hum.Animator:LoadAnimation(weapon.Animation)
	track.Priority = Enum.AnimationPriority.Action
	track:Play()
	local sound = Instance.new("Sound",char)
	sound.SoundId = weapon.SwingSoundID
	sound:Play()
	local sound2 = Instance.new("Sound",char)
	sound2.SoundId = weapon.HitSoundID
	local hrp = char.PrimaryPart
	local newHitbox = hitbox:Clone()
	task.wait(track.Length/2)
	newHitbox.CFrame = hrp.CFrame * CFrame.new(0,0,-newHitbox.Size.Z/2)
	newHitbox.Parent = workspace
	local parts = workspace:GetPartsInPart(newHitbox)
	local humanoidsHit = {}
	for _, hit in parts do
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid and humanoid ~= hum and not table.find(humanoidsHit,humanoid) and not game.Players:GetPlayerFromCharacter(hit.Parent) then
			table.insert(humanoidsHit,humanoid)
			humanoid:TakeDamage(weapon.Damage)
			damageEffect:FireClient(plr,hit.Parent)
			if not sound2.IsPlaying then
				sound2:Play()
			end
			
		end
	end
	sound.Ended:Once(function()
		sound:Destroy()
	end)
	newHitbox:Destroy()
	
end

return Melee
1 Like

No reply :frowning: but 15 views so sad does anyone know the problem?

1 Like

first of all, format the code, don’t expect any bit of help when you can’t even put any bit of effort into detailed topic, see you next 15 views later.

Oh sorry, it just did that when i pasted it in

Ok done I just realized how to do it

Where is this script located, server or client.
Is the weapon an actual ‘Tool’ class?
Are you sure the logic is getting to the Play location in the script, such as did you put a print(“hi”) statement to see if its actually reaching that point?

I think I see “FireClient” in there, if this is an animation being played on the character, it really needs to be played client side.

It is a module in replicated storage but the function is fired by the server, and weapon is just a configuration with all the information, also I think it gets to the play part because i hear the sound

So I need to play it on client side, there isnt any way to play it on server and other players probably cant see it right when i play it on the client?

Any client side animation on the character will replicate to all clients, so everyone will be able to see it.

Wow good to know ill try it right now

Weird, im playing the animation track on the client now but it still wont show

Sorry I fell asleep. Is the code the same, or can you post your modified code? I will see if I can get the module to play for me.

I see the problem, you are not waiting for the animation to fully load before playing it.
after the load, do something like.

--load animation here
while track.Length <= 0 do task.wait() end
--play animation here

I have this local script here that im using to play the animation, here it is
i did what you said and it still wont play, im on r6 and the animation is r6 so its not that, also track.IsPlaying returns true

local rep = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local remotes = rep:WaitForChild("RemoteEvents")
local configurations = rep:WaitForChild("Configurations")
local weapons = configurations:WaitForChild("Weapons")
local meleeConfig = weapons:WaitForChild("Melee")
local rangedConfig = weapons:WaitForChild("Ranged")
local attack = remotes:WaitForChild("WeaponAttack")
local equip = remotes:WaitForChild("EquipWeapon")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local gui = script.Parent
local weaponUi = gui.RightShop.Weapon
local image = weaponUi.WeaponImage
local damage = weaponUi.Damage
local hitspeed = weaponUi.Hitspeed
local currentWeapon = nil

uis.InputBegan:Connect(function(input,gameProcessed)
	if gameProcessed then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		local info = require(meleeConfig:FindFirstChild(currentWeapon))
		if not info then
			info = require(rangedConfig:FindFirstChild(currentWeapon))
		end
		local track = char.Humanoid.Animator:LoadAnimation(info.Animation)
		track.Priority = Enum.AnimationPriority.Action
		--load animation here
		while track.Length == 0 do task.wait() end
		--play animation here
		track:Play()
		print(track.IsPlaying)
		attack:FireServer(currentWeapon)
	end
end)

local function equipWeapon(weaponName)
	equip:FireServer(weaponName)
	local info = require(meleeConfig:FindFirstChild(weaponName))
	if not info then
		info = require(rangedConfig:FindFirstChild(weaponName))
	end
	if not info then return end
	currentWeapon = weaponName
	image.Image = info.Icon
	damage.Text = tostring(info.Damage).." ⚔️"
	hitspeed.Text = tostring(info.HitSpeed).." ⏰"
end


equipWeapon("Rusty Pipe")

I found a solution, I saw a video on youtube to change my game from r15 to r6 but it only changed the animation packs so it looked like r6 but was r15 the whole time

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.