Hello! I’m making a mechanic where you are trapped in a freezer, and slowly your skin becomes more and more blue. However, I have no idea on how to do this and no idea where to even start!
Can someone help point me in the right direction? Thanks.
Hello! I’m making a mechanic where you are trapped in a freezer, and slowly your skin becomes more and more blue. However, I have no idea on how to do this and no idea where to even start!
Can someone help point me in the right direction? Thanks.
Color3 values have a :Lerp() function that lets you gradually change between two colors. So you can lerp between the players original color and blue.
How would I get their body colors?
I think you can just use the color of the actual parts, so like the character’s Head.Color
would i just do it like this?
script.Parent.Door.ClickDetector.MouseClick:Connect(function(plr)
plr.Character:FindFirstChild('Head').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
plr.Character:FindFirstChild('Torso').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
plr.Character:FindFirstChild('RightLeg').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
plr.Character:FindFirstChild('LeftLeg').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
plr.Character:FindFirstChild('LeftArm').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
plr.Character:FindFirstChild('RightArm').Color:Lerp(Color3.new(0.0313725, 0.662745, 1))
end)
You could also tween it.
I am not sure if Lerp or Tweening is more efficient, but I only understand Tweening.
You are missing an alpha and aren’t assigning the colour to anything. Alpha is the percentage between colour 1 and colour 2.
So for example,
local TIME_TO_FREEZE = 120 -- say it takes 120 seconds for them to fully freeze
local FROZEN_COLOUR = Color3.new(0.0313725, 0.662745, 1) -- the colour the player will be when they are fully frozen
-- now to get the colour for each body part:
local head = character:FindFirstChild('Head')
local bodyColour = head.Color
-- timeElapsed on the following line would be the duration for which they were in the freezer or began freezing
-- we clamp the alpha between 0 and 1 since we wouldn't want to extrapolate if timeElapsed > TIME_TO_FREEZE, or if timeElapsed < 0
local colourInterpolated = bodyColour:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
head.Color = colourInterpolated
-- assign colourInterpolated to the rest of the body parts
Where is TimeElapsed variable?
timeElapsed would be the time that they’ve been in the freezer or started freezing (so just increment it every frame or so)
I would recommend iterating over the values with code similar to this:
for _, i in plr.Character:GetChildren() do
if i:IsA("Part") then
-- Change colour of `i`
end
end
How would I count the time?? I’m kinda bad at scripting so lol. thank you for the help btw!!
local timeElapsed = 0
while isInFreezer do
timeElapsed += task.wait()
end
Where and how would I add this? The entire line of code is after the while true do, and it won’t run.
It would depend how your code is set up but you’d probably do something like this:
local TIME_TO_FREEZE = 120 -- say it takes 120 seconds for them to fully freeze
local FROZEN_COLOUR = Color3.new(0.0313725, 0.662745, 1) -- the colour the player will be when they are fully frozen
-- now to get the colour for each body part:
local head = character:FindFirstChild('Head')
local headColour = head.Color
local timeElapsed = 0
local isFreezing = false
local function updateColour()
local colourInterpolated = bodyColour:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
head.Color = colourInterpolated
-- assign colourInterpolated to the rest of the body parts
end
script.Parent.Door.ClickDetector.MouseClick:Connect(function()
isFreezing = not isFreezing
if isFreezing then
while isFreezing do
timeElapsed += task.wait()
updateColour()
end
else
timeElapsed = 0
updateColour()
end
end)
Thanks for this, however it appears that I just instantly turn blue! Do you know why this is happening? There is no errors in the output
I have modified the code a little bit so it applies to every part in the body and it fits my situation. However, I am pretty sure I did not break it to be causing this. Just in case, here is my modified code of yours.
-- timeElapsed on the following line would be the duration for which they were in the freezer or began freezing
local TIME_TO_FREEZE = 20 -- say it takes 20 seconds for them to fully freeze
local FROZEN_COLOUR = Color3.new(0.0313725, 0.662745, 1) -- the colour the player will be when they are fully frozen
local timeElapsed = 0
local isFreezing = false
local function updateColour(plr)
-- now to get the colour for each body part:
local head = plr.Character:FindFirstChild('Head')
local ra = plr.Character:FindFirstChild('Right Arm')
local la = plr.Character:FindFirstChild('Left Arm')
local rl = plr.Character:FindFirstChild('Right Leg')
local ll = plr.Character:FindFirstChild('Left Leg')
local t = plr.Character:FindFirstChild('Torso')
local colourInterpolated = head.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
local colourInterpolated1 = ra.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
local colourInterpolated2 = la.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
local colourInterpolated3 = rl.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
local colourInterpolated4 = ll.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
local colourInterpolated5 = t.Color:Lerp(FROZEN_COLOUR, math.clamp(timeElapsed / TIME_TO_FREEZE, 0, 1))
head.Color = colourInterpolated
ra.Color = colourInterpolated1
la.Color = colourInterpolated2
rl.Color = colourInterpolated3
ll.Color = colourInterpolated4
t.Color = colourInterpolated5
-- assign colourInterpolated to the rest of the body parts
end
script.Parent.Door.ClickDetector.MouseClick:Connect(function(plr)
isFreezing = not isFreezing
if isFreezing then
while isFreezing do
timeElapsed += task.wait()
updateColour(plr)
end
else
timeElapsed = 0
updateColour(plr)
end
end)
You can try to use a Highlight
as well if that works for you. There are some issues with this, but it should work. Make sure the depth mode is set to Occluded
. If you parent it to a model without setting an adornee the entire model will be highlighted.
But i want the skin color itself to turn blue, I don’t want a highlight.