Hello. I am currently making a game, and every frame I am firing a raycast from the character down. As you can see in the video, the newly instanced parts are not being detected by the raycast. Why is this?
(I am printing the result of the raycast)
The blue part is called “Territory”, and as you can see the raycast detects it perfectly. However, the raycasts do not detect the newly instanced parts called BIP, they only detect the part below them, called Map. The newly instanced parts are at the same Y level as the blue part, so I am unsure why my raycast is not detecting them.
Thanks in advance for all help!
Could you show parts of the code and the raycast parameters?
game:GetService("RunService").RenderStepped:Connect(function()
if true then
char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
local dir = Vector3.new(0,-10,0)
local result = workspace:Raycast(hrp.Position, dir, params)
if result then -- see if the raycast has hit anything
if result.Instance then
local part = result.Instance
print(part)
end
end
end
end)
I don’t get the use of if true then
and if result.Instance
, seems like just nesting if statements. Aside from that the code looks fine to me.
Dont worry, I know what the problem was - the parts I wanted to detect were part of the player’s character, which is part of the raycastparams, which was why they weren’t being detected.
2 Likes