Raycast not working

It’s not working
So I want to print out part at instance of raycast

But is not working

repeat wait() until game.Players.LocalPlayer:FindFirstChild("Character")

while wait() do

local e = workspace:Raycast(game.Players.LocalPlayer.Character.HumanoidRootPart.Position,game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector*40)

print('sa')

print(e.Instance.Name)

end

Character is a property of player, not a child.

So you should do

local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local client = Players.LocalPlayer
local character = client.Character or client.CharacterAdded:Wait() -- if the character doesn't exist, wait for it

while true do
    local result = Workspace:Raycast(character.PrimaryPart.Position, character:GetPrimaryPartCFrame().LookVector*40)
    print(result and result.Instance) -- WorldRoot:Raycast returns nil if nothing was hit by ray
    wait() -- not sure why you are waiting this short but ok
end