sort of, otherway round for me. Bottom line they cause issues with raycasting.
Maybe because Accessories of the players are most likely /CanCollide = false
If you parented them to currentcamera would it make a difference?
RayCasting only works with CanCollide = true objects just like making a OnTouched Door it wont work unless you have it on CanCollide = true
i wouldn’t think so,it will still seem the same
As he said,well you can ignore them
Why not make it so if the object hit’s Parent is an Accessory, then you can set it it to a different parent.
It seems like a pretty easy fix to me. Obviously, modify it to match with your game
Here is an example to get the idea:
obj.Touched:Connect(function(hit)
local playerHit
if hit.Parent:FindFirstChild('Humanoid') then
playerHit = hit.Parent
elseif hit.Parent:IsA('Accessory')
playerHit = hit.Parent.Parent
end
playerHit.Humanoid:TakeDamage() -- blah blah blah or whatever you use to make them take damage
end)
It is hitting via Raycasting. The problem is it doesnt seem to want to hit anything at all, bullets go through. And what you are saying is basically so accessories add to the characters hitbox, that makes the game unfair.
Could it be that the Handle part of the headgear makes the Ray go “This is inside the blacklist, ignore!” and ignores the fact that a head is inside of it?
I’m not sure but if you could do some experimental coding you could try to use whitelists instead to see if that fixes things.
tested with lazer gun from tutorial on wiki, so far it successfully ignores all accessories.
all the objects and their descendants are ignored
local IgnoreList = {}
function scanHats(char)
for _,v in pairs(char:GetChildren()) do
if v:IsA("Accessory") then
table.insert(IgnoreList,v)
end
end
end
for _,v in pairs(game.Players:GetChildren()) do
v.CharacterAdded:Connect(function(char)
--wait(1) -- this will not be needed on serverside as I was testing the code on client which obviously has some latency before all accessories appear
scanHats(char)
end)
if v.Character then
pcall(function() scanHats(v.Character) end)
end
end
Sorry I wasn’t aware that it wasn’t working through Raycasting.
You have two methods of fixing this:
-
Using what other people suggested, you should just add a table of accessories to the ignore list. If you find that this is an interference, which it shouldn’t be, you can just create a table of accessories when the player joins (in a server script) and access it through a bindable event (alternatively use a module) and just update it when they die to account for an update to their accessories.
-
FindPartOnRayWithWhitelist where you can set a whitelist to the player’s head or other body part and it should work well with this.
Just found the fix lol, well, almost definite fix.
for _,v in pairs(workspace.CharactersFolder.:GetDescendants()) do
if v.Parent:IsA(“Accessory”) then
v.Size = Vector3.new(0,0,0)
end
end
Unless u guys have an even better solution this is the best i could find, thanks for ur input
Well, 2 people (@artfvl & @AdvancedDrone) have now mentioned that you could add the accessory to the ignorelist to make it work.
if Descendant:IsA("Accessory") then table.insert(IgnoreList, Descendant) end
I did that and it didnt make a difference
If IgnoreList doesn’t work with FindPartOnRayWithIgnoreList then there might be something wrong with the code.
Uh you know you could of done this incase it hits the hats :
local damages = {
Head = 15,
Torso = 10,
Else = 5
}
local torsoTypes = {
UpperTorso = true,
LowerTorso = true,
Torso = true,
HumanoidRootPart = true
}
local function getDamage(hit)
if not hit then return end
if hit and ((hit.Parent and hit.Parent:IsA("Accessory")) or hit:IsA("Accessory") or hit.Name == "Head") then
return damages.Head
end
if torsoTypes[hit.Name] then
return damages.Torso
end
return damages.Else
end
If you’re checking if it’s an Accessory and the user fires the gun at their BackAccessory, it would still register as a head shot. I would recommend checking if Hit has a HatAttachment (or whatever Attachments are on the head).
Uhh idk how this got bumped, was definitely something wrong with my code back then but I have a simple trick to getting around hitting accessories.
local ig = {} -- ignore list
function Raycast(p1,p2,dist)
local ray = Ray.new(p1, (p2 - p1).unit * dist)
local part, position,normal = workspace:FindPartOnRayWithIgnoreList(ray, ig, false, true)
if part.Parent:IsA("Accessory") then
table.insert(ig,part) -- adds to the ignore list
return Raycast(p1,p2,dist) -- do the raycast again
else
return part,position,normal
end
end
Bumping this thread because while it works, now there are newer and better methods than recasting the ray and performing an if statement check.
Now you can just add the accessory to a collision group or disable CanQuery for them to make raycast just not hit them at all.
Works for both new and old raycast methods as by default they are in the Default collision group.