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
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)