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

(SOLVED) Raycast doesn't get an npc at all?

Asked by
harstud 218 Moderation Voter
3 years ago
Edited 3 years ago

hi. i've written this script where it gets the nametag of an npc and puts it on a textlabel. when it gets the part/npc, it sends the name and parent name. but this doesn't work?

gif of the error: as you can see at the bottom left at the end of the gif, nothing is being outputted when my mouse is directly on the npc. i've tried everything to get this to work https://gyazo.com/6b5197cd95f4e3345ff1066ce10a1d96

localscript that is meant to make the nametag appear

game:GetService("RunService").RenderStepped:Connect(function()
    local mouse = game.Players.LocalPlayer:GetMouse()

    mouse.TargetFilter = nil
    script.Parent.Namez.Position = UDim2.new(0, mouse.X, 0, mouse.Y)

    local mouseUnitRay = mouse.UnitRay
    local ray = Ray.new(mouseUnitRay.Origin, mouseUnitRay.Direction * 1000)
    local Target, position = game.ReplicatedStorage.GetRay:InvokeServer(ray, {})

    if Target then
        if Target.Parent.Parent == workspace.Zombies then
            script.Parent.Namez.character.Text = Target.Parent.Name
            script.Parent.Namez.level.Text = "Enemy"
            script.Parent.Namez.Visible = true
        elseif game.ReplicatedStorage:FindFirstChild(Target.Parent.Parent.Name) then
            script.Parent.Namez.character.Text = Target.Parent.Parent.Name
            script.Parent.Namez.level.Text = "Level ".. string.sub(Target.Parent.Name, #Target.Parent.Name - 1)

            script.Parent.Namez.Visible = true
        else
            script.Parent.Namez.Visible = false
        end
    else
        script.Parent.Namez.Visible = false
    end
end)

script that actually sends the ray

local function FindPart(plr, ray, list)
    local Target ,Position = workspace:FindPartOnRay(ray)
    pcall(function() print(Target.Name) print(Target.Parent.Name) end)

    return Target,Position
end

local GetRay = game:GetService("ReplicatedStorage").GetRay

GetHealth.OnServerInvoke = ReturnHealth

1 answer

Log in to vote
0
Answered by
harstud 218 Moderation Voter
3 years ago

Solved, problem was with collision groups.

Ad

Answer this question