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

Help with mouse.target to change material whilst the mouse is hovering over the block?

I'm trying to have it where whilst the player is hovering over the characters head it will turn into a neon material I have no clue how I would go about doing this, help would be appreciated. :)

local plr = game.Players.LocalPlayer
local Char = plr.Character
local mouse = plr:GetMouse()

mouse.Move:Connect(function()
	local target = mouse.Target
-- I think i would have to have a loop here
end)

1 answer

Try this, the formatting sucks on the website. Click "view source" to make it look better, it also looks better in studio.

Let me know if it works, I haven't tested it.

--removed unnecessary character variable
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Move:Connect(function()
	wait() -- added a wait to prevent possible lag
	local target = mouse.Target
	if target.Parent:FindFirstChild("Humanoid") and target.Parent:FindFirstChild("Head") then -- if the mouse's Target is over a player and if the plr has a head then
		target.Parent.Head.Material = Enum.Material.Neon -- changes the head material to neon
	else
		target.Parent.Head.Material = Enum.Material.SmoothPlastic -- if the mouse is not on the head anymore, it changes the material back
	end
end)


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