Ok, I changed it to where it uses only one script.
ChargeTool.rbxl (57.8 KB)
local tool = script.Parent
local character = nil
local humanoid = nil
local hrp = nil
local hitbox = nil
local sound = nil
local hitsound = nil
local hitEvent = nil
local isCharging = false
local cooldown = false
local Force = nil
local damageAmount = 15
function StopCharge()
isCharging = false
sound:Stop()
if Force then
Force:Destroy()
Force = nil
end
end
function DoHit(part)
if isCharging then
if part.Parent:FindFirstChild("Humanoid") then
local targetChar = part.Parent
if targetChar.Name ~= character.Name then
StopCharge()
hitsound:Play()
print(targetChar)
local targetHum = targetChar:FindFirstChild("Humanoid")
if targetHum then
targetHum:TakeDamage(damageAmount)
end
end
else
StopCharge()
hitsound:Play()
print(part.Name)
end
end
end
tool.Equipped:Connect(function()
character = tool.Parent
humanoid = character:WaitForChild("Humanoid")
hrp = character.PrimaryPart
--create a hitbox
if character:FindFirstChild("Hitbox") then
character.Hitbox:Destroy()
end
hitbox = Instance.new('Part')
hitbox.Transparency = 0.7
hitbox.CanCollide = false
hitbox.Name = "Hitbox"
hitbox.Size = Vector3.new(4,4,4)
hitbox.CFrame = hrp.CFrame * CFrame.new(0, 0, 0)
hitbox.Massless = true
local weld = Instance.new("WeldConstraint")
weld.Part1 = hitbox
weld.Part0 = hrp
weld.Parent = hitbox
hitbox.Parent = character
hitEvent = hitbox.Touched:Connect(DoHit)
--create sounds
sound = Instance.new('Sound')
sound.SoundId = "http://www.roblox.com/asset/?id=111896685"
sound.Parent = tool.Parent.Head
hitsound = Instance.new('Sound')
hitsound.SoundId = "rbxassetid://9118612665"
hitsound.Parent = tool.Parent.HumanoidRootPart
end)
tool.Unequipped:Connect(function()
if Force then
Force:Destroy()
Force = nil
end
if hitEvent then
hitEvent:Disconnect()
hitEvent = nil
end
if hitbox then
hitbox:Destroy()
hitbox = nil
end
if sound then
sound:Destroy()
sound = nil
end
if hitsound then
hitsound:Destroy()
hitsound = nil
end
end)
tool.Activated:Connect(function()
if not cooldown then
cooldown = true
isCharging = true
sound:Play()
if Force then
Force:Destroy()
end
Force = Instance.new("BodyVelocity")
Force.maxForce = Vector3.new(88800, 0, 88800)
Force.Parent = hrp
Force.Velocity = hrp.CFrame.LookVector*60
humanoid.AutoRotate = false
-- humanoid.WalkSpeed = 0 -- temp
task.wait(2)
StopCharge()
humanoid.AutoRotate = true
-- humanoid.WalkSpeed = 16 -- temp
task.wait(5)
cooldown = false
end
end)