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

Rays not working as expected?

Asked by 4 years ago

So I'm trying to make a script that will find out if the player is visible. I tried using rays but they don't seem to point at the player for some reason?

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character


while wait() do
    game.Workspace.Folder.visual1.Position = game.Workspace.Folder.main.CFrame.Position
    game.Workspace.Folder.visual2.Position = plr.Character.Head.CFrame.Position
    game.Workspace.Folder.main.CFrame = CFrame.new(game.Workspace.Folder.main.CFrame.Position,plr.Character.Head.Position)
    local raycasted = Ray.new(game.Workspace.Folder.main.Position,plr.Character.Head.CFrame.Position)
    local parts = {game.Workspace.Folder.main,game.Workspace.Folder.visual,game.Workspace.Folder.visual1,game.Workspace.Folder.visual2}
for i,v in pairs(plr.Character:GetChildren()) do    if v:IsA("BasePart") and not parts[v] then table.insert(parts,v)    end end
if game.Workspace:FindPartOnRayWithIgnoreList(raycasted,parts) then
local part, position = game.Workspace:FindPartOnRayWithIgnoreList(raycasted,parts)
game.Workspace.Folder.main.BrickColor = BrickColor.new("Bright green")
print(part.Name)
game.Workspace.Folder.visual.Position = position
else
    game.Workspace.Folder.visual.Position = Vector3.new(0,100,0)
    game.Workspace.Folder.main.BrickColor = BrickColor.new("Black")
    end end

any solutions or other methods to fix this?

Answer this question