ima be honest, i was trying to make a script for a baseball bat weapon, got most of my code from a few youtube videos, and stitched them together
can someone help me understand whats happening in line 20? if you want to find the specific line quickly, i left a pretty big comment on the line im talking about. im trying to fix a bug thats caused by whatever is going on in that line of code but if i cant understand whats happening then i cant fix it
if theres anymore info you need (ex. ragdoll module script code, etc…) i can add them
(the script is located inside of the Tool object for the weapon)
local tool = script.Parent
local bat = tool.BatModel
local damage_re = tool:WaitForChild("SwingEvent")
local hitsound = bat.BatHit
local ragdollmodule = require(game:GetService("ServerScriptService").Ragdoll)
local kbmodule = require(game:GetService("ServerScriptService").Knockback)
local hitbox = Instance.new("Part",tool)
local connection = nil
local hitlist = {}
local function inflict_damage(other_object)
if(not hitlist[other_object.Parent]) then
local humanoid = other_object.Parent:FindFirstChild("Humanoid")
if humanoid then
hitlist[other_object.Parent] = true
humanoid:TakeDamage(25)
kbmodule.Start(humanoid.Parent, (humanoid.Parent.HumanoidRootPart.Position - other_object.Position).Unit * Vector3.new(60,40,60) + Vector3.new(0,40)) --THIS IS THE LINE I DONT UNDERSTAND, the parameters for this function are (character,direction)
ragdollmodule.Start(humanoid.Parent)
for i in hitlist do
hitsound:Play()
end
wait(2)
ragdollmodule.Stop(humanoid.Parent)
end
end
end
damage_re.OnServerEvent:Connect(function()
local hitbox = Instance.new("Part",tool)
hitbox.Size = Vector3.new(1,5,1)
hitbox.CanCollide = false
hitbox.Massless = true
hitbox.Transparency = 0.7 --debug
local weld = Instance.new("Weld",hitbox)
weld.Part0 = bat
weld.Part1 = hitbox
game.Debris:AddItem(hitbox,0.4)
hitlist = {}
connection = hitbox.Touched:Connect(inflict_damage)
end)
since the bug seems to be happening with the kbmodule thing, heres also the module script code for knockback in case it has something to do with that
(located in server script service)
local kb = {}
function kb.Start(character,direction)
local hrp = character:FindFirstChild("HumanoidRootPart")
if hrp == nil then return end
local att = Instance.new("Attachment",hrp)
local lv = Instance.new("LinearVelocity",att)
lv.MaxForce = 9999999
lv.VectorVelocity = direction
lv.Attachment0 = att
game.Debris:AddItem(att,0.1)
end
return kb