what i want this script to do is detect if it hits a part. and if it does it will check if its a player. and if it isnt it will create a hitbox and destroy the fireball (havent scripted that part yet) but it only works if it hits a rig. if it hits a part not apart of a rig it doesnt detect as touched
local plrs = game:GetService('Players')
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce then return end
if plrs:GetPlayerFromCharacter(hit.Parent) then return end
if plrs:GetPlayerFromCharacter(hit.Parent.Parent) then return end
debounce = true
local hitbox = Instance.new('Part')
hitbox.Name = 'FireballHitbox'
script.Parent:Destroy()
end)
In case you want to detect if a part is a descendant of a character, you may want to use this piece of code:
local currentParent = hit
local humanoid
repeat
humanoid = currentParent:FindFirstChild("Humanoid")
currentParent = currentParent.Parent
until currentParent == workspace or humanoid
if humanoid then
-- There's a humanoid found, run code here when it's about a character/player character
-- humanoid.Parent will be the character found
else
-- Non-humanoid part
end
Then there’s nothing wrong with the code, you should check carefully groupcollisions in case you changed anything about it, and also try to enable cancollide temporally to test it
You are moving the fireball 3 units every 0.025 frames.
Parts that are between those 3 units may not get detected as what the moving does is that it INSTANTLY moves the part
Thin walls may not get detected, you may consider using something like raycasting/shapecasting
Another alternative would be the raycasthitbox module, really useful module that can be used for melee or other miscellaneous items such as projectiles.
i tried with this module. i made the part move only one stud every 0.005 or so seconds. i made sure to add the dmg points and set the detection mode to part mode but it still doesnt detect anything. (cantouch and canquery is enabled on everything and there are no other collision groups made)
local offset = CFrame.new(0,0,-1)
local RaycastHitbox = require(game:GetService('ReplicatedStorage').RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent)
Hitbox.DetectionMode = RaycastHitbox.DetectionMode.PartMode
Hitbox.Visualizer = true
Hitbox.OnHit:Connect(function(hit, humanoid)
print(hit.Name)
if humanoid then
print('hum')
else
print('nonhum')
end
end)
while true do
script.Parent.CFrame = script.Parent.CFrame:ToWorldSpace(offset)
task.wait(0.005)
end
You have to call Hitbox:HitStart() once for it to indefinitively cast rays. Whenever you want to stop casting rays with the module, call Hitbox:HitStop()