Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

 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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.