local plr = game.players.LocalPlayer
local Mouse = plr:GetMouse()
local currentColor = --ur parts color here
local hovering = false
if Mouse.Target:IsA("Part") and Moust.Target.Name == "parts name here" then
Mouse.Target.Color = Color3.Random()
hovering = true
if hovering == false then
Mouse.Target.Color = currentColor
end
end
Mouse target does work, the problem was that @Zenqpa was not adding a connection to check if the mouse got moved, so he only checked once. Here is a working script(put in localscript in starterplayerscript):
local NORMAL_COLOR = Color3.fromRGB(255, 85, 0)
local HOVER_COLOR = Color3.fromRGB(255, 0, 0)
local Part = workspace:WaitForChild("Part") -- put your part here, this is for the test.
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
Part.Color = NORMAL_COLOR
mouse.Move:Connect(function()
if mouse.Target == Part then
Part.Color = HOVER_COLOR
else
Part.Color = NORMAL_COLOR
end
end)
local part = game.Workspace.Part
local originalColor = part.Color
local hoverColor = Color3.fromRGB(0, 0, 0)
local clickDetector = Instance.new("ClickDetector", part)
clickDetector.CursorIcon = "rbxassetid://" -- if you don't want a special cursor when hovering
clickDetector.MouseHoverEnter:Connect(function()
part.Color = hoverColor
end)
clickDetector.MouseHoverLeave:Connect(function()
part.Color = originalColor
end)
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local mouse = player.GetMouse()
local oldColor
local oldPart
local function rand()
return math.random(0, 255)
end
mouse:GetPropertyChangedSignal("Target"):Connect(function()
oldPart.Color = oldColor
local mouseTag = mouse.Target
if mouseTag:IsA("Part") then
oldPart = mouseTag
oldColor = mouseTag.Color
mouseTag.Color = Color3.new(rand()/255, rand()/255, rand()/255) --random color when hovered
end
end)
This only fires whenever the mouse hovers over a new part, unlike the other implementation which fires whenever the mouse is moved (even if already hovered over the part).
There is a slight problem with @Limited_Unique idea. First he wrote the function wrong using a dot and not a :
Also my testing with the script shows that getpropertychangedsignal does not work with mouse Target so I had to make my own detection script and here is the final result:
local NORMAL_COLOR = Color3.fromRGB(255, 85, 0)
local HOVER_COLOR = Color3.fromRGB(255, 0, 0)
local Part = workspace:WaitForChild("Part") -- put your part here, this is for the test.
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local rs = game:GetService("RunService")
Part.Color = NORMAL_COLOR
local lastTarget = nil
rs.Heartbeat:Connect(function()
if lastTarget ~= mouse.Target then
lastTarget = mouse.Target
print("target changed")
if mouse.Target == Part then
Part.Color = HOVER_COLOR
else
Part.Color = NORMAL_COLOR
end
end
end)