#raycast returns wrong thing

1 messages · Page 1 of 1 (latest)

lavish valley
#

just going to paste the important things:

`function SHOOT()

local DIRECTION = (MOUSE.Hit.Position - WEAPON_RAYCAST_START.Position).Unit * 10000

--[[rayparams ]]

local RAYCAST = workspace:Raycast(WEAPON_RAYCAST_START.Position, DIRECTION, RAY_PARAMETERS)
local RAY_RESULT
if RAYCAST then
    RAY_RESULT = RAYCAST.Instance.Parent
end

local RAY_PLAYER
if RAY_RESULT and RAYCAST then
    if RAY_RESULT:FindFirstChildOfClass("Humanoid") then
        RAY_PLAYER = RAY_RESULT:FindFirstChildOfClass("Humanoid")
        SHOOT_EVENT:FireServer(RAYCAST, RAY_RESULT, RAY_PLAYER)
    end
end
print(RAY_RESULT)

end`

now, i have a rig for the gun to shoot at. And for the first few times i fire the event, the raycast returns the rig, but after a few shots it starts to always return workspace

yes, i have made the rayparams, normalized it and added *10000

cursive apex
#

Whatever your hitting is a child of workspace instead of a child of a character

#

Add print(RAYCAST.Instance) after the raycast and it might make more sense

#

Also please format your code correctly, It was a pain to read

lavish valley
#

the script IS formatted but thats just how it pasted

cursive apex
# lavish valley the script IS formatted but thats just how it pasted

I mean paste it in discord correctly
Like this

function SHOOT()
    
    local DIRECTION = (MOUSE.Hit.Position - WEAPON_RAYCAST_START.Position).Unit * 10000
    
--[[rayparams ]]
    
    local RAYCAST = workspace:Raycast(WEAPON_RAYCAST_START.Position, DIRECTION, RAY_PARAMETERS)
    local RAY_RESULT
    if RAYCAST then
        RAY_RESULT = RAYCAST.Instance.Parent
    end
    
    local RAY_PLAYER
    if RAY_RESULT and RAYCAST then
        if RAY_RESULT:FindFirstChildOfClass("Humanoid") then
            RAY_PLAYER = RAY_RESULT:FindFirstChildOfClass("Humanoid")
            SHOOT_EVENT:FireServer(RAYCAST, RAY_RESULT, RAY_PLAYER)
        end
    end
    print(RAY_RESULT)
    
end
cursive apex
lavish valley
lavish valley
#

AND

lavish valley
cursive apex
#

whats it hitting?

lavish valley
#

well

#

sometimes it hits what im aiming at, sometimes the baseplate

#

but im not moving the mouse at all

cursive apex
#

Try spawning a part along the ray

#

so you can visualize it

lavish valley
#

alr

#

i kept moving between the part and the rig

#

and it started saying baseplate

#

while i was aiming at the part