You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to create a hit box to my punching animation.
The hitbox appears when the event on the animation has been passed.
- What is the issue? Include screenshots / videos if possible!
When I try to get the LeftArm of the character but I get nil.
local Players=game:GetService("Players")
print("this is raycast script")
--this is the attempt to get the elft arm of the character
Players.PlayerAdded:Connect(function(player)
print("player added")
local MyCharacter = player.Character or player.CharacterAdded:Wait()
local Humanoid = player.Character:WaitForChild("Humanoid")
script.Parent=MyCharacter
local allowed = {
"Left Arm"
}
for _, Obj in pairs(MyCharacter:GetChildren()) do
if table.find(allowed, Obj.Name) ~= nil then
script.Parent=Obj
local LeftArm=Obj -- gives nil for some reason
print("script has been parented2")
end
end
end)
local RS=game:GetService("ReplicatedStorage")
local hitboxEvent=RS.eventsAndFunctions.hitboxEvent
-- << Initial Setup >>
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
-- We will construct a new hitbox for our part
local newHitbox = RaycastHitbox.new(script.Parent)
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {MyCharacter} --so that My character doesnt dammage himself from his own punch lol
Params.FilterType = Enum.RaycastFilterType.Blacklist
-- Makes a new event listener for raycast hits
newHitbox.OnHit:Connect(function(hit, humanoid)
print(hit)
humanoid:TakeDamage(50)
end)
-- at a certain part of animation we will create event when start fire ray cast
hitboxEvent.OnServerEvent:Connect(function(player,JabAnimationTrack)
print("on server event :)")
newHitbox:SetPoints(LeftArm, {Vector3.new(0, 0, 0)})
newHitbox:HitStart()
JabAnimationTrack.Stopped:Connect(function() -- when anim ends stop the hit box
newHitbox:HitStop()
end)
end)
also the script does recognize the left arm as it’s parent