You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I would like to make a line of code that excludes the player as a target of the ray and only the other npcs/players
What is the issue? doesnt work
What solutions have you tried so far? numerous relational operators, if statements, functions, nothing works.
NOTE: this script only works during mobile test mode and the local script is placed in starter character scripts
local UIS = game:GetService("UserInputService")
local camera = workspace.Camera
local filter = {}
UIS.TouchTapInWorld:Connect(function(position, processed)
local ray = camera:ViewportPointToRay(position.X, position.Y, 0)
ray = Ray.new(ray.Origin, ray.Direction * 500)
local target, point, surface = workspace:FindPartOnRayWithIgnoreList(ray, filter)
print(target)
end
local player = game.PLayers.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- And on the ignore list:
local target, point, surface = workspace:FindPartOnRayWithIgnoreList(character, ray, filter)
I added an optional feature in the new ignore list that I’ve created for you, in case you use bullets or want selected parts to be ignored
Try this (havent bugtested it yet)
local UIS = game:GetService("UserInputService")
local camera = workspace.Camera
local filter = {}
local UIS = game:GetService("UserInputService")
local camera = workspace.Camera
local SetupIgnoreList = function()
local List = {}
local Character = game.Players.LocalPlayer.Character
for _, v in pairs(Character:GetChildren()) do
if v:IsA("Accessory") or v:IsA("MeshPart") or v:IsA("Part") then
table.insert(List, v)
end
end
--[[
(OPTIONAL)
Create folder, name it 'IgnoredItems', or whatever you want, and put it in workspace
This will make it so that there are multiple parts in workspace that are ignored
If you do happen to add rays or bullets, then I suggest you put them in this IgnoredItems folder
Code:
for _, v in pairs(game.Workspace.IgnoredItems:GetChildren()) do
table.insert(List, v)
end
]]--
return List
end
UIS.TouchTapInWorld:Connect(function(position, processed)
local ray = camera:ViewportPointToRay(position.X, position.Y, 0)
ray = Ray.new(ray.Origin, ray.Direction * 500)
local IgnoreList = SetupIgnoreList()
local target, point, surface = workspace:FindPartOnRayWithIgnoreList(ray, IgnoreList)
print(target)
end
but if you would like to stick with the deprecated one, add your character to the filter list.
I made a quick module for this:
local QuickCast = {}
QuickCast.__index = QuickCast
function QuickCast.new(Parameters)
local self = setmetatable({}, QuickCast)
self.RaycastParameters = Parameters
return self
end
function QuickCast:Cast(Origin, Direction)
local NewRay = workspace:Raycast(Origin, Direction, self.RaycastParameters)
return NewRay or {
Instance = nil,
Position = Origin + Direction,
Material = Enum.Material.Air,
Normal = nil
}
end
return QuickCast
The above uses rayparams, which is for the latest version of raycasting