I need help understanding a line in my own code

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)
1 Like

Well what happens when you sucessfully damage someone?

It’s called kbmodule so I’m guessing it stands for knockback

1 Like

whats supposed to happen is when the hitbox touches an enemy player, they take 25 damage and they are ragdolled + knocked back, the bug is that sometimes the player thats hit kinda just disappears from the game when they are hit sometimes

I don’t get it, they didnt dissapear from the game also the knockback looks like its not even working either they’re just stay in place and getting ragdolled

This seems like its using a module script, try to find that and look at what it does.

honestly i think the knockback effect actually happening bugged too since sometimes it just doesnt happen
i made another recording of the disappearing thing happening more clearly

1 Like

bro sent those dummies to the backrooms

yeah im not sure maybe it’s the knockback thats too strong possibly, check the module or show it’s code so we can see what’s happening

2 Likes

just like that other guy said i looked through the knockback module and i have no idea what the issue is
code for it:
(maybe i just dont understand how MaxForce works but even when i set it to something much lower the bug still happens)

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
1 Like