I have been having problems with this bat script, I do not know how to fix it.
I came on the devfourm to ask for help.
LocalScript:
local WeaponTool = script.Parent
local player
local char – Blank Variable that will be Assigned Later (if still nil)
script.Parent.Equipped:Connect(function()
print(“Weapon Equipped”)
if char == nil then
player = game:GetService("Players").LocalPlayer
print(player.Name .. " owns the weapon!")
char = player.Character or player.CharacterAdded:Wait()
print(char.Name .. "'s character has been found!")
end -- Assigns Player And Character Variables
game.ReplicatedStorage.ConnectM6D:FireServer(WeaponTool.Weapon)
local torso = char:FindFirstChild("Torso")
if torso then
print("Torso Exists")
else
print("NO TORSO FOUND")
return
end -- Searches For Torso
local ToolGrip = torso:FindFirstChild("ToolGrip")
if ToolGrip then
print("ToolGrip Found")
else
print("ToolGrip NOT FOUND")
return
end -- Searches for Tool Grip
ToolGrip.Part0 = torso
ToolGrip.Part1 = WeaponTool.Weapon -- Sets Part0 and Part1
end)
WeaponTool.Unequipped:Connect(function()
game.ReplicatedStorage.DisconnectM6D:FireServer()
end)
Script:
wait(0.1)
local plr = script.Parent.Parent.Parent
local char = plr.Character
local idle = char.Humanoid:LoadAnimation(script.Animations.Idle)
local equipped = false
local attacking = false
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV2)
local Hitbox = RaycastHitbox:Initialize(script.Parent.Weapon)
durability = 7
local attack1 = char.Humanoid:LoadAnimation(script.Animations.Attack1)
local broken = false
Hitbox.OnHit:Connect(function(hit, humanoid)
if humanoid.Parent ~= char and humanoid.Parent.Handler.Infected.Value == true then
script.Parent.Weapon.Hit:Play()
local damage = math.random(15,35)
local Speed = 25
local Force = 40000
local TotalForce = Force
local KnockBack = Instance.new(“BodyVelocity”,hit.Parent:FindFirstChild(“Torso”))
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = plr.Character:FindFirstChild(“HumanoidRootPart”).CFrame.LookVector * Speed – based on the direction YOUR character is facing.
game.Debris:AddItem(KnockBack,0.1)
humanoid:TakeDamage(damage)
humanoid.Parent.Actions.Stunned.Value = true
if durability == 0 then
Hitbox:HitStop()
script.Parent.Weapon.Transparency = 1
script.Parent.Weapon.B:Play()
script.Parent.Weapon.ParticleEmitter:Emit(50)
game.ReplicatedStorage.EditGUI:FireClient(plr,“text”,“Your baseball bat broke.”)
broken = true
idle:Stop()
attack1:Stop()
wait(2)
script.Parent:Destroy()
end
durability = durability - 1
end
end)
script.Parent.Equipped:Connect(function()
if not plr.Character.Actions.Stunned.Value == true and not broken then
idle:Play()
equipped = true
else
plr.Character.Humanoid:UnequipTools()
end
end)
script.Parent.Unequipped:Connect(function()
idle:Stop()
equipped = false
end)
script.Parent.Activated:Connect(function()
if not attacking and equipped and not plr.Character.Actions.Stunned.Value == true and durability >= 0 then
attack1:Play()
attacking = true
script.Parent.Weapon.Prepare:Play()
wait(0.16)
Hitbox:HitStart()
script.Parent.Weapon.Swing:Play()
wait(0.4)
Hitbox:HitStop()
wait(2)
attacking = false
wait(0.4)
end
end)
plr.Character.Actions.Stunned.Changed:Connect(function()
plr.Character.Humanoid:UnequipTools()
end)
DM me on discord if you need to contact me : Someone else#3350
Screenshots below
|
|
/

