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

Why does it not print yes everytime mouse is touching my players character or any players character?

Asked by 4 years ago
 local Player = game.Players.LocalPlayer
 local Mouse = Player:GetMouse()
 Mouse.TargetFilter = nil

while wait() do
 if Mouse.Target and Mouse.Target:IsDescendantOf(game.Players.LocalPlayer.Character) then

    print("yes")
    else
        print("no")
    end

 end

it doesnt print yes when my mouse touches a player

1 answer

Log in to vote
0
Answered by 4 years ago

Try something like this:

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local Player = Players.LocalPlayer

local Mouse = Player:GetMouse()
local textbox = nil -- set textbox here

while true do
    local startPos = Mouse.Origin.Position
    local endPos = Mouse.Hit.Position 
    local ray = Ray.new(startPos, endPos - startPos)

    local part = Workspace:FindPartOnRay(ray)

    if part and part.Parent and part.Parent:IsA("Model") then
        local found = Players:GetPlayerFromCharacter(part.Parent) 

        if found then
            textbox.Text = found.Name
        end
    end

    wait(0.1)
end
Ad

Answer this question