Hi Devforum, I’m learning to program and I’ve encountered a problem where BodyVelocity isn’t working and I don’t know why. Additionally, TakeDamage isn’t working either.
The .Touched event only accepts one parameter: hit, not the Humanoid. The hit part will be a child of the Character. In order to get the Humanoid from the hit part you will first have to get the Character and then the Humanoid inside the character.
local Hitbox = require(ReplicedStorage.MuchachoHitbox)
local hitbox = Hitbox.CreateHitbox()
hitbox.Size = Vector3.new(10.4, 13.7, 7.2)
hitbox.CFrame = origin
hitbox.Visualizer = false
hitbox.Touched:Connect(function(hit)
local Humanoid: Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then
return
end
Humanoid:TakeDamage(100)
print(hit)
local HitEffect = ReplicedStorage.Assets.VFX.HitEffect:Clone()
HitEffect.CFrame = hit.Parent.HumanoidRootPart.CFrame
HitEffect.Parent = workspace.VFX
HitEffect.Attachment.Crescents:Emit(3)
HitEffect.Attachment.Debris:Emit(12)
HitEffect.Attachment.Flash:Emit(1)
HitEffect.Attachment.Shardes:Emit(16)
local bv = Instance.new("BodyVelocity")
bv.Parent = hit.Parent.HumanoidRootPart
bv.MaxForce = Vector3.new(1,1,1) * math.huge
bv.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 100
Debirs:AddItem(bv, .1)
end)
hitbox:Start()
wait(.7)
hitbox:Stop()
This code should work, let me know if you need anything else.
You messed up the name of the service, it’s Debris. Unless your variable is called Debirs. Can you show me where you define the variable for the Debris service?
There we get the hit variable inside the function connected to the .Touched event, but when you set the velocity of the BodyVelocity you use a variable called Character that is never defined in the script. Is this the full script? If it isn’t, I’ll have to add some things.
I agree, it would be a better choice but BodyVelocity should work. I don’t understand why it’s working for me and not for him when the code looks functional.