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 add blacklist for accesories and ignore list for some stuff to ray
What is the issue? Well i have no idea how to do so
What solutions have you tried so far? i tried looking on forums, dev hub and yt after i realised i cannot slove it by myslef, im starting in programming and i dont have very much knowledge.
the code:
local cam = workspace.CurrentCamera
local mousePos = inputService:GetMouseLocation()
local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
mouseRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
local target, hit = workspace:FindPartOnRay(mouseRay)
if hit then
print("hit")
else
print("miss")
end
also can someone give me a hint on where to place attachment 1 location for beam for bullet visuals that ill do later, im saying it here to dont make 2 topics if i have issues with finding it later on.
If your just trying to see if a player has some sort of attachment then just raycast to see if the parent of the object is a Player with a Humanoid and then check their accessories.
im trying to add ignore list to this ray so it ignore, player holding tool and tool parts (ik how to get these 2 just â:GetChildren()â), but idk how to make an ignore list and ignore the accesories
its suposed to work as bullet like to stop at any non transparent obstacle and dmg players + ignore gun and player shooting it, im not sure how to add this ignore list so it wont block on the gun and player shooting it
local UIS = game:GetService("UserInputService")
local StuffYouDontWant = workspace.StuffYouDontWant
local function mouseRaycast()
local mousePos = UIS:GetMouseLocation()
local mouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.BlackList
raycastParams.FilterDescendantsInstances = {StuffYouDontWant} -- Put objects here
local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
return raycastResult
end
I recommend using the new collision groups like so:
You could use ignore list but its difficult to get all the accessories in workspace and put it in one table while also constantly updating it for new ones. (though you could use collection services)
Something like @WhiteOut_RBLX mentioned with parent checking, but uses recasting the ray multiple times which seems less efficient than collision groups (havent done performance tests yet).
Then use a blacklist with your player being the only object in there
Then in the script just make a check that sees if the part is a part of another player and if its not then just dont do anything
Or you could make a script that also turns off CanTouch in every accessory the player has and you wont have to care because the ray wonât be able to hit them.
so i can like put table i stuff i dont want, i guess but how to ignore any item wich parent is accesory? or i shoud get first ancestor wich is model and check if it have humanoid?
I made this:
if raycastResult.parent:FindFirstChild(âHumanoidâ) then
event:FireServer(raycastResult.parent:FindFirstChild(âHumanoidâ))
elseif raycastResult.parent:IsA(âAccesoryâ) then
event:FireServer(raycastResult:FindFirstAncestorIsA(âModelâ):FindFirstChild(âHumanoidâ))
else
but i get this:
âparentâ is not a valid member of RaycastResult
if raycastResult then
print("Object/terrain hit:", raycastResult.Instance:GetFullName())
print("Hit position:", raycastResult.Position)
else
print("Nothing was hit!")
end
thx now ik how to do rest just 1 last question to what i shall parent attachment 2 and to what i shall set its location to get acurate beam as visual
(aslo i have to do this in script to get it visable for everyone not in local one, i shall use event for that i guess but how i shall move variables to visual script to dont make it messy)