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. the module script code, video of the bug happening, 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)