local camera = game.Workspace.CurrentCamera
local duration = 0.5
local tween = 0
local lastHit = nil
function tweenColor(newColor)
local currentColor = script.Parent.BackgroundColor3
local r, g, b = currentColor.r, currentColor.g, currentColor.b
local newR, newG, newB = newColor.r, newColor.g, newColor.b
tween = tween + 1
local tweenNum = tween
local timer = tick()
spawn(function ()
repeat
local i = (tick()-timer)/duration
i = i > 1 and 1 or i
local iR, iG, iB = r + ((newR - r) * i), g + ((newG - g) * i), b + ((newB - b) * i)
script.Parent.BackgroundColor3 = Color3.new(iR, iG, iB)
game:GetService'RunService'.RenderStepped:wait()
until (tick()-timer) >= duration or tweenNum ~= tween
end)
end
function findFirstPart()
local ignore = {game.Players.LocalPlayer.Character}
local start, finish = camera.CoordinateFrame.p, (camera.CoordinateFrame * CFrame.new(0, 0, -1)).p
local ray = Ray.new(start, (finish-start).unit * 100)
local hit, pos
repeat
hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignore)
table.insert(ignore, hit)
until hit == nil or hit.Transparency <= 0
return hit
end
while wait() do
local hit = findFirstPart()
if hit and hit ~= lastHit then
lastHit = hit
tweenColor(hit.BrickColor.Color)
end
end
Server script would actually connect to RenderStepped fine in Play Solo.
If the local script is connecting to RenderStepped while the script is not parented to PlayerGUI etc. (I think this may happen when player respawns) this could happen - so maybe if you’re using RenderStepped:wait() in a loop player respawn breaks it.
I’ve run into this issue before actually. RunService.RenderStepped works with server sided scripts on the client while in build for whatever the reason.
That’s weird, because I know that RunService.RenderStepped actually does work on regular server sided scripts on the client while in build, however not online servers.