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 my raycast to behave normally
What is the issue? Include screenshots / videos if possible!
It is giving me this bug: nil 1227.9871826171875, -3.4028234663852886e+38, 851.6358642578125 0, 0, 0 Enum.Material.Air
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
No one has had this problem, suprisingly
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local UserInputService = game:GetService("UserInputService")
local RP = game:GetService("ReplicatedStorage")
local canClick = true
local Raycastparams = RaycastParams.new()
Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
Raycastparams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
local Player =game.Players.LocalPlayer.Character
function Aim()
local Player =game.Players.LocalPlayer.Character
local cursorPosition = game:GetService("UserInputService"):GetMouseLocation()
local oray = game.workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)
--local ray = Ray.new(game.Workspace.CurrentCamera.CFrame.p,(oray.Direction * 1000))
local ray = workspace:Raycast(Player.HumanoidRootPart.Position, oray.Direction * 1000)
print(ray.Instance)
return ray.Instance
end
while true do
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and canClick == true then
canClick = false
local part = Aim()
if part ~= nil and part.Parent ~= nil and part.Parent.Parent ~= nil and part.Parent ~= Player and Player:FindFirstChild("ScopedRifle") then
if part.Parent:FindFirstChild("Humanoid") then
RP:FindFirstChild("keyPressed"):InvokeServer("Gun",part.Parent)
elseif part.Parent.Parent:FindFirstChild("Humanoid") and part.Parent.Parent.Parent ~= Player then
RP:FindFirstChild("keyPressed"):InvokeServer("Gun",part.Parent.Parent)
end
end
wait(0.1)
canClick = true
end
end)
task.wait(0.1)
end
I would also like the ray to ignore the player’s entire character
local Player = game.Players.LocalPlayer.Character
local cursorPosition = game:GetService("UserInputService"):GetMouseLocation()
local oray = game.workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsType = {Player}
local ray = workspace:Raycast(Player.HumanoidRootPart.Position, oray.Direction * 1000, params)
if ray.Instance then
return ray.Instance
end
told it to print what it was hitting the return of aim, and it gives this:nil -212.3601531982422, -3.4028234663852886e+38, 1477.05712890625 0, 0, 0 Enum.Material.Air . I am not clicking on anything other than the baseplate.
also, if I climbed up higher, it gave me actual results. All I’m trying to do here is cast a ray from the character, and check if it hit another character.
local Player = game.Players.LocalPlayer.Character
local Mouse = game.Players.LocalPlayer:GetMouse()
local cursorPosition = Mouse.Hit.Position
local oray = game.Workspace.CurrentCamera:ViewportPointToRay(cursorPosition.x, cursorPosition.y, 0)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsType = {Player}
local ray = workspace:Raycast(Player.HumanoidRootPart.Position, oray.Direction * 1000, params)
if ray and ray.Instance then
return ray.Instance
end
I think something about the direction of the ray is messed up, how about just checking if the camera can see it? How would I do that? I mean, it’s definently casting a ray, but it just does it in the wrong direction