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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)


Ad

Answer this question