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