I’m making a script that keeps an hitbox on the soap bar and it has this to keep running and as soon as it hits any player part aslong as they aren’t alredy ragdolled they ragdoll them, but I don’t know why it starts working for 2 seconds then suddenly only detects the baseplate or just dosent detect the legs
local d = false
while task.wait() do
local hits = workspace:GetPartsInPart(script.Parent.Hitbox)
for i,hit in hits do
if d then continue end
d = true
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health <= 0 then continue end
print("A")
if hit.Parent:GetAttribute("Ragdoll") then continue end
print("hit")
task.spawn(function()
hit.Parent:SetAttribute("Ragdoll",true)
end)
hit.Parent.HumanoidRootPart:ApplyImpulse((hit.Parent.HumanoidRootPart.CFrame.LookVector+Vector3.new(0,0.2,0)*power))
end
d = false
end
end
the ragdoll atribute is to tell another script to ragdoll the player but as you can see i make it print out any hit whos parent has an humanoid and it prints nothing when the soap hits the legs
I would recommend positioning the hitbox once and welding it to the soap, then unanchoring it so it can perform physics calculations by itself without needing a moving part
Use a WeldConstraint, set the hitbox position to the soap, set the part0 to the hitbox, part1 to the soap, unanchor the hitbox, set the hitbox to massless
The only reason that would be is if the weldconstraint isnt parented right or has its Part1 or Part0 set wrong, try running the script and track the WeldConstraint to make sure
Also if this is the only time you actually need to use this soap you could already have the Hitbox and weldconstraint set up inside the data model, without using script to create everything afterwards
The code is a bit messy, but I believe it’s because you continue if Health is <= 0 or the attribute Ragdoll is true, which results in d never getting set back to false, and the loop constantly skipping the rest of the code.
I would also suggest using BasePart.Touched events rather than constantly performing expensive spatial queries.
If you need help cleaning up the code, I can help with that too.
This post was about me recommending return instead of continue but that will also end the whole function, you’ll have to use the debounce with an if-statement in the for loop
Edit: That may very well count for all the other uses of continue too in this case since continue ends a for loop completely im pretty sure