Need help with melee weapon

why doesnt the sword damage the humanoid unless im really close and even then it doesnt damage sometimes

https://gyazo.com/956a40c6e6c47a7fe706c6258055ae74

local Weapon = {}

--local function createOwner(npcModel: Model)
--	local userid = game.Players.LocalPlayer.UserId
	
--	local OwnerAttribute = npcModel:GetAttribute("Owner")
--	npcModel:SetAttribute(OwnerAttribute, userid)
--end

local function createRayCast(tool)
	local Damage = tool.Stats:WaitForChild("PhysicalDamage")
	
	local distance = 10
	local rayparams = RaycastParams.new()
	rayparams.FilterType = Enum.RaycastFilterType.Exclude
	rayparams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
	
	local ray =	workspace:Raycast(game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position, tool.Handle.Position * distance, rayparams)
	
	if ray then
		local rayInstance = ray.Instance
		local model = rayInstance:FindFirstAncestorOfClass("Model")
		
		if model then
			--createOwner(model)
			if model:FindFirstChild("Humanoid") then
				model:FindFirstChild("Humanoid"):TakeDamage(Damage.Value)
			end
			--model:FindFirstChild("Humanoid").Died:Connect(function()
			--	print("Npc Died")
			--end)
		end	
	end
end

Weapon.Init = function(tool: Tool, Character)
	local newTool = tool:Clone()
	newTool.Parent = Character
end

Weapon.Attack = function(tool)
	local Anims = {
		tool.Animations:WaitForChild("Animation1"),
		tool.Animations:WaitForChild("Animation2"),
		tool.Animations:WaitForChild("Animation3"),
		tool.Animations:WaitForChild("Animation4")
	}
	
	local humanoid = tool.Parent:WaitForChild("Humanoid") 
	local animator = humanoid:WaitForChild("Animator")
	local animtrack = nil

	for index, anim in pairs(Anims) do
		animtrack = animator:LoadAnimation(anim)
	end

	if animtrack ~= nil then
		print("Playing animation...")
		animtrack:Play()
		createRayCast(tool)
	end
end

return Weapon
  • how do i play the animations in order
  • fix raycast function
1 Like

bro we cant help you if you wont provide us code

nvm u edited it last second i posted this

2 Likes

if u wanna play animations in order then considering using variables (stages) and enable them or set the stage higher and higher with checks ( im on mob rn )

1 Like

i tried this but it still only plays one animation

Weapon.Attack = function(tool)
	local Animation1 = tool.Animations:WaitForChild("Animation1")
	local Animation2 = tool.Animations:WaitForChild("Animation2")
	local Animation3 = tool.Animations:WaitForChild("Animation3")
	local Animation4 = tool.Animations:WaitForChild("Animation4")

	local humanoid = tool.Parent:WaitForChild("Humanoid") 
	local animator = humanoid:WaitForChild("Animator")
	local currentAnim = 1
	local animTrack = nil

	if currentAnim == 1 then
		animTrack = humanoid:LoadAnimation(Animation1)
		currentAnim = 2
	elseif currentAnim == 2 then
		animTrack = humanoid:LoadAnimation(Animation2)
		currentAnim = 3
	elseif currentAnim == 3 then
		animTrack = humanoid:LoadAnimation(Animation3)
		currentAnim = 4
	elseif currentAnim == 4 then
		animTrack = humanoid:LoadAnimation(Animation4)
		currentAnim = 1
	end

	if animTrack then
		animTrack:Play()
	end
end

can you print the animtrack and show me the output?

and make sure that all animationids are different for each obj

i put the variable outside the function and it works now BUT the raycast is still broken

The second argument of :Raycast() is the direction of the ray, try doing the Handle’s position - Humanoidrootpart’s position * distance instead.