For some odd reason when testing my sword it keeps adding 9 extra kills on top of the base 1.
I’ve tried just making it do plus .1 on kill instead of the base one as an easy fix
leaderstats.Kills.Value = leaderstats.Kills.Value + 1
reaplaced with
leaderstats.Kills.Value = leaderstats.Kills.Value + .1
But, that causes my gui to freak out some
The script below should be the only ones that need to fixed show how
Main Script
local rp = game:GetService("ReplicatedStorage")
local combat = rp:WaitForChild("SwordCombat")
local sounds = script.SwordSounds
local handler = require(script.CombatHandler)
combat.OnServerEvent:Connect(function(Player, sequence)
local character = Player.Character
local h = character.Humanoid
local humrp = character.HumanoidRootPart
local sword = character:FindFirstChild("Sword")
if sword then
local plrAnim, swordAnim, length = handler.getAnimation(h,sword.Controller, sequence)
plrAnim:Play()
swordAnim:Play()
plrAnim:GetMarkerReachedSignal("Hit"):Connect(function()
handler.Attack(Player,character,humrp,length,sequence)
print(sequence)
end)
task.delay(length, function()
combat:FireClient(Player)
end)
end
end)
Module Script
local Animations = script:WaitForChild("Animations")
local plr = Animations.plr
local swrd = Animations.Sword
local meshes = script.Meshes
local rp = game:GetService("ReplicatedStorage")
local KeyProvider = game:GetService("KeyframeSequenceProvider")
local debris = game:GetService("Debris")
local VFX = rp:WaitForChild("VFX")
local SSS = game:GetService("ServerScriptService")
local dictonaryHandler = require(SSS:WaitForChild("DictonaryHandler"))
local handler = {
plrsInCombat = {},
plrStunTime = {},
plrAnims = {
["L"] = plr.R6_Slash1,
["LL"] = plr.R6_Slash2,
["LLL"] = plr.R6_Slash3
},
SwordAnims = {
["L"] = swrd.R6_Sword1,
["LL"] = swrd.R6_Sword2,
["LLL"] = swrd.R6_Sword3
},
SwordHitboxes = {
["L"] = CFrame.Angles(0, 0, math.rad(90)),
["LL"] = CFrame.Angles(0, 0, math.rad(90)),
["LLL"] = CFrame.Angles(0, 0, math.rad(130))
}
}
function handler.getAnimation(Humanoid,SwordAnimationController, sequence)
local length = 0
local keysuquence = KeyProvider:GetKeyframeSequenceAsync(handler.plrAnims[sequence].AnimationId)
local keyframes = keysuquence:GetKeyframes()
for i=1, #keyframes do
local Time = keyframes[i].Time
if Time > length then
length = Time
end
end
return Humanoid.Animator:LoadAnimation(handler.plrAnims[sequence]), SwordAnimationController.Animator:LoadAnimation(handler.SwordAnims[sequence]), length
end
function handler.Attack(Player,character,humrp,length,sequence)
local folder = Instance.new("Folder")
folder.Name = "SwordCombat"
folder.Parent = workspace
debris:AddItem(folder, .25)
local hitbox = meshes.HitBox:Clone()
hitbox.Size = Vector3.new(2,7,3)
hitbox.Transparency = 1
hitbox.CFrame = humrp.CFrame * CFrame.new(0,0,-2) * handler.SwordHitboxes[sequence]
hitbox.Parent = folder
local weld1 = Instance.new("ManualWeld")
weld1.Name = "HitboxW"
weld1.Part0 = hitbox
weld1.Part1 = humrp
weld1.C0 = weld1.Part0.CFrame:ToObjectSpace(weld1.Part1.CFrame)
weld1.Parent = weld1.Part0
local connection
connection = hitbox.Touched:Connect(function() end)
local results = hitbox:GetTouchingParts()
coroutine.wrap(function()
for _, object in pairs(results) do
if not object:IsDescendantOf(character) then
local Eh = object.Parent:FindFirstChild("Humanoid")
local Ehmrp = object.Parent:FindFirstChild("HumanoidRootPart")
if Eh and Ehmrp and Eh.Health > 0 then
hitbox:Destroy()
print("p")
if handler.plrsInCombat[character] or dictonaryHandler.find(character, "Stunned") then
return
end
if connection then
connection:Disconnect()
end
Eh:TakeDamage(10)
Eh.Died:Connect(function()
local leaderstats = Player.leaderstats
print(Player,"Killed",Eh.Parent)
leaderstats.Kills.Value = leaderstats.Kills.Value + .1
end)
coroutine.wrap(function()
for _, plr in pairs(game.Players:GetChildren()) do
VFX:FireClient(plr,"SwordVFX","vfx",Ehmrp)
end
end)()
local duration
if string.len(sequence) < 4 then
duration = length * 2
else
duration = length * 3
end
if not handler.plrsInCombat[Eh.Parent] then
handler.plrsInCombat[Eh.Parent] = os:clock()
handler.plrsInCombat[Eh.Parent] = duration
dictonaryHandler.add(Eh.Parent, "Stunned")
print("p3")
Eh.WalkSpeed = 10
else
handler.plrsInCombat[Eh.Parent] = os.clock()
handler.plrStunTime[Eh.Parent] = duration
Eh.WalkSpeed = 10
end
end
end
end
end)()
task.delay(.25, function()
if connection then
connection:Disconnect()
print("p4")
end
end)
end
return handler
Thanks to anyone who can help find the problem