I am trying to create a Gui tween that increments based on player distance from a set point. The best example is from the experience called “your last thoughts at the end of time” https://www.roblox.com/games/5889471811/your-last-thoughts-at-the-end-of-time
where the further you get from the spawn the color correction gets more red and more saturated. I want to implement something similar as an out of bounds prevention, or just to prevent the player from wandering too far from the objective. The effect would be a gui in the form of “static” like from a tv or camera instead of a post processing effect. They used a radius as a sort of “safe zone” where the effect is not happening. I have a perfect circle radius of lets say 2000 (the exact number is 2030 but I could just change the math) and I want it so that when their distance from the origin is greater than that 2000 their gui transparency tweens down from 1 (fully invisible) to 0.6 (slightly visible) based on distance.
The graphic shows possibly the best explanation of what I mean.
local tweenInfo1 = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false);
local tweenIn = TweenService:Create(gui, tweenInfo1, {ImageTransparency = 0.6})
local tweenOut = TweenService:Create(gui, tweenInfo1, {ImageTransparency = 1})
--distance
wait(2) --load character
local Position1 = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
local centerpart = workspace.centerpart.Position
game:GetService("RunService").Heartbeat:Connect(function()
local magnitude = (Position1 - centerpart).Magnitude
if magnitude >= 2030 then
tweenIn:Play()
elseif magnitude <= 2030 then
tweenOut:Play()
end
end)
I don’t think I’m on track with what I have so far. This script would only have it tween up to that desired transparency even if you weren’t moving further away and were on the 2001 stud distance. I would need an equation that takes the extra distance on top of that 2000 distance safe zone and does the math to know how much to tween by per stud of what my graphic showed which was 200. A problem I was having is that when I would print the magnitude it would just print the value I was at when loading in and repeat it for the rest of the games ticks instead of updating when it changes. Another slightly more abstract problem is that the player will spawn outside of the safe zone and the script needs to be enabled when entering that radius which could probably be done with a collision detection.
Is there a better way to approach this that I’m not seeing?