Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with Raycasting (Unable to cast instance to Vector3?)

Asked by
Foxxive 10
3 years ago

Hello. I am working on my slender man Roblox game (yes, still, believe it or not) and i am trying to get raycast stuff working to trigger a GUI when slender man is being looked at.

However, whenever I test, it gives me the same output error: “Unable to cast instance to Vector3” I have been trying to fix this, but I cannot get any ideas as to what it could be. Here is the script (or, well, a part of it):

while wait() do

local mag;

local range = game.Lighting.FogEnd - 2;

local cansee = true

local DummyHead = workspace.Slenderman["Meshes/thehead"]

coroutine.wrap(function()
    while wait() do
        mag = (c.Torso.Position - DummyHead.Position).magnitude;
    end
end)()

local WG = workspace.Slenderman

coroutine.wrap(function()
    while wait() do
        local Position, CanSee = camera:WorldToScreenPoint(workspace.Slenderman["Meshes/thehead"])
        if CanSee and mag <= range and cansee then 

any help is appreciated, thank you in advance

1 answer

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
3 years ago

Your issue is on line 21.

local Position, CanSee = camera:WorldToScreenPoint(workspace.Slenderman["Meshes/thehead"])

WorldToScreenPoint requires a Vector3, however, you are giving the "Meshes/thehead" instance instead. Assuming "Meshes/thehead" is a basepart, you could do something like this:

local Position, CanSee = camera:WorldToScreenPoint(workspace.Slenderman["Meshes/thehead"].Position) 

Adding a reference to the Instance's Position property (Vector3)

Ad

Answer this question