hi, it’s 3 days i’m working on this effect, but it just seems not to work
What do you want to achieve? i’m trying to make a system where the player must understand that the object they are getting close to is dangerous. The object is going to be white, and the closer the player gets to it, the redder the block becomes
What is the issue? i just don’t know how to make it work
What solutions have you tried so far? i tried looking for solutions on the forum, and using magnitude, but the effect I get is that when the player approaches the block suddenly turns red, while what I want to achieve is that the closer the player is, the more red the block is, so this also includes intermediate colors between the initial white and red
please, any answer is appreciated, and could be the one to help me, i’m really struggling at this
local player = game.Players.LocalPlayer
local part -- fill in variable
local eventrange = 20
local originalcolor = part.Color
game:GetService("RunService").RenderStepped:Connect(function()
local rootpos = player.Character.HumanoidRootPart.Position
part.Color = originalcolor:Lerp(Color3.new(1,0,0),
1 - math.clamp((rootpos - part.Position).Magnitude / eventrange), 0, 1)
end)
If its turning red suddenly you just need to scale the values:
local whiteDistance = 100 --Part completely white at this distance
local redDistance = 20 --Part completely red at this distance
local whitenes = math.clamp((distance - redDistance) / whiteDistance, 0.0, 1.0)
block.Color3 = Color3.new(1.0, whitenes , whitenes) --When whiteness is lower the part looks redder
thanks, i’m gonna try it when i get home (2h max) in the meanwhile, would you tell me where to put the local script please? i read something online and i know it can be placed in different services, where would this one go to?
i don’t know. i did put the local script in StarterPlayerScript, as i read it can be there, this is the script.
local player = game.Players.LocalPlayer
local part = game.Workspace.Part -- fill in variable
local eventrange = 37
local originalcolor = part.Color
game:GetService("RunService").RenderStepped:Connect(function()
local rootpos = player.Character.HumanoidRootPart.Position
part.Color = originalcolor:Lerp(Color3.new(1,0,0),
1 - math.clamp((rootpos - part.Position).Magnitude / eventrange), 0, 1)
end)
local player = script.Parent
local part = game.Workspace.Part -- fill in variable
local whiteDistance = 225 --Part completely white at this distance
local redDistance = 0.01 --Part completely red at this distance
local waitTime = 0.05 -- set this to the delay time between each time you check the distance
while task.wait(waitTime) do
if player then
local distance = (player.HumanoidRootPart.Position - part.Position).Magnitude
local whitenes = math.clamp((distance - redDistance) / whiteDistance, 0.0, 1.0)
part.Color = Color3.new(0.6, whitenes , whitenes) --When whiteness is lower the part looks redder
end
end