I cannot fix the issue that causes the players to clip through parts when playing the sword animations, please help.
local re = game.ReplicatedStorage:WaitForChild("SwordReplicatedStorage"):WaitForChild("SwordRE")
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
repeat task.wait() until char:FindFirstChild("RightHand")
local m6d = Instance.new("Motor6D")
m6d.Name = "SwordMotor6D"
m6d.Parent = char:WaitForChild("RightHand")
m6d.Part0 = char.RightHand
end)
end)
local playerCombos = {}
re.OnServerEvent:Connect(function(plr, instruction, sword)
local char = plr.Character
if char and sword and char:FindFirstChild("Humanoid") and char.Humanoid.Health > 0 then
if instruction == "ConnectM6D" and sword.Parent == char then
char.RightHand.SwordMotor6D.Part1 = sword.BodyAttach
elseif instruction == "DisconnectM6D" then
char.RightHand.SwordMotor6D.Part1 = nil
playerCombos[plr] = nil
if char:FindFirstChild("BLOCKING") then
char["BLOCKING"]:Destroy()
end
elseif instruction == "attack" and sword.Parent == char then
local currentCombo = (playerCombos[plr] and playerCombos[plr][1] or 0) + 1
local lastAttacked = playerCombos[plr] and playerCombos[plr][2] or 0
if tick() - lastAttacked > 0.4 then
if currentCombo > 4 and tick() - lastAttacked < 1.3 then
return
end
if currentCombo > 4 then
currentCombo = 1
end
playerCombos[plr] = {currentCombo, tick()}
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {char}
local ray = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * 12, rayParams)
task.spawn(function()
if ray then
local humanoid = ray.Instance.Parent:FindFirstChild("Humanoid") or ray.Instance.Parent.Parent:FindFirstChild("Humanoid")
if humanoid then
task.wait(currentCombo == 4 and 0.3 or 0.1)
if not humanoid.Parent:FindFirstChild("BLOCKING") then
local damage = currentCombo == 4 and 30 or 10
humanoid:TakeDamage(damage)
local dmgSound = game.ReplicatedStorage.SwordReplicatedStorage.DamageSound:Clone()
dmgSound.Parent = ray.Instance
dmgSound:Play()
dmgSound.Ended:Connect(function()
dmgSound:Destroy()
end)
local blood = game.ReplicatedStorage.SwordReplicatedStorage.BloodParticles.Attachment:Clone()
blood.Parent = ray.Instance
blood.Position = ray.Instance.Position - ray.Position
game:GetService("Debris"):AddItem(blood, 0.2)
end
if game.Players:GetPlayerFromCharacter(humanoid.Parent) then
re:FireClient(game.Players:GetPlayerFromCharacter(humanoid.Parent), "camera shake")
end
end
end
end)
task.spawn(function()
local swingSound = game.ReplicatedStorage.SwordReplicatedStorage:FindFirstChild("Swing" .. currentCombo .. "Sound"):Clone()
swingSound.Parent = sword.BodyAttach
if currentCombo == 4 then
task.wait(0.2)
end
swingSound:Play()
swingSound.Ended:Connect(function()
swingSound:Destroy()
end)
end)
re:FireClient(plr, "swing animation", currentCombo)
task.spawn(function()
if currentCombo == 4 then
task.wait(0.24)
else
task.wait(0.06)
end
sword.BodyAttach.Attachment.SlashParticles.Rotation = NumberRange.new(-73 + sword.BodyAttach.Orientation.Z)
sword.BodyAttach.Attachment.SlashParticles.Enabled = true
task.wait(0.1)
sword.BodyAttach.Attachment.SlashParticles.Enabled = false
end)
task.wait(1)
if currentCombo == playerCombos[plr][1] then
playerCombos[plr] = nil
end
end
elseif instruction == "sprint" then
if not char:FindFirstChild("SPRINTING") then
local sprintingValue = Instance.new("BoolValue")
sprintingValue.Name = "SPRINTING"
sprintingValue.Parent = char
else
for _, child in pairs(char:GetChildren()) do
if child.Name == "SPRINTING" then
child:Destroy()
end
end
end
elseif instruction == "block" and sword.Parent == char then
local blockValue = Instance.new("BoolValue")
blockValue.Name = "BLOCKING"
blockValue.Parent = char
elseif instruction == "stop block" then
for _, child in pairs(char:GetChildren()) do
if child.Name == "BLOCKING" then
child:Destroy()
end
end
end
end
end)