So I’m trying to make a script that turns bricks blue whenever its being hovered on. It does work but it loops so it flickers. Heres the script
LocalScript:
local mouse = plr:GetMouse()
local hoverable = {workspace.BRICK2, workspace.BRICK}
local HOVER_COLOR = BrickColor.Blue()
local BRICKCOLORS = {}
local hover = false
for i, brick in ipairs(hoverable) do
BRICKCOLORS[brick.name] = brick.BrickColor
end
mouse.Move:Connect(function()
if table.find(hoverable, mouse.Target) then
if (mouse.Target.BrickColor == BRICKCOLORS[mouse.Target.Name] and hover == false) then
mouse.Target.BrickColor = HOVER_COLOR
hover = true
else
mouse.Target.BrickColor = BRICKCOLORS[mouse.Target.Name]
hover = false
end
end
end) ```
for i, brick in ipairs(Parts) do
NORMAL_COLORS[brick.name] = brick.Color
end
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local rs = game:GetService(“RunService”)
local lastTarget = nil
rs.Heartbeat:Connect(function()
if lastTarget ~= mouse.Target then
lastTarget = mouse.Target
print(“target changed”)
if table.find(Parts, mouse.Target) then
mouse.Target.Color = HOVER_COLOR
else
mouse.Target.Color = NORMAL_COLORS[mouse.Target.Name]
end
end
end)
So, i tried to do this if table.find(Parts, mouse.Target) then Parts[mouse.Target.Name].Color = HOVER_COLOR else Parts[lastTarget.Name].Color = NORMAL_COLORS[mouse.Target.Name] end but ended up not working I was wondering how do i exactly fix this? The error was Players.Seth6131926.PlayerGui.LocalScript:26: attempt to index nil with 'Name' oh nevermind then!
So hovering on it works now, but unhovering doesn’t heres the error Players.Seth6131926.PlayerGui.LocalScript:24: attempt to index nil with 'Name'
Wait nevermind I tried storing the individual rgb color codes for i, brick in ipairs(Parts) do NORMAL_COLORS[brick.name] = { brick.Color.R, brick.Color.G, brick.Color.B, } end and apply it like this lastTarget.Color = Color3.fromRGB(NORMAL_COLORS[lastTarget.name].R, NORMAL_COLORS[lastTarget.name].G, NORMAL_COLORS[lastTarget.name].B) but i got this error instead Players.Seth6131926.PlayerGui.LocalScript:28: attempt to index nil with 'R'
local NORMAL_COLOR = Color3.fromRGB(255, 85, 0)
local HOVER_COLOR = Color3.fromRGB(255, 0, 0)
local plr = game.Players.LocalPlayer
local hoverable = {workspace.BRICK2, workspace.BRICK}
local HOVER_COLOR = BrickColor.Blue()
local mouse = plr:GetMouse()
local rs = game:GetService("RunService")
local CurrentPart
rs.Heartbeat:Connect(function()
if table.find(hoverable,mouse.Target) then
CurrentPart = mouse.Target
CurrentPart.BrickColor = HOVER_COLOR
else
if CurrentPart ~= nil then
CurrentPart.BrickColor = BrickColor.new("Medium stone grey")
CurrentPart = nil
end
end
end)