How can I make player walkspeed slower when approaching a part?

In my game, there is something the player has to approach.

But, I want the player to grow slower and slower as they approach the thing. Are there any ways to do this effectively? The method I’m using now is pretty ineffective/messy, as I have parts on the ground that alter the character’s walkspeed when they touch it.

Also, I would like to apply this effect with other things like FOV, lighting settings, and Sound Playbackspeed.

If anyone can help, I would greatly appreciate it. Thanks

Yes this is possibly! Use magnitude to do it. Here’s an example I drafted up for you,

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Target = workspace:WaitForChild("Target")
local MaxWalkSpeed = 16
local MinWalkSpeed = 4
local MaxDistance = 100

local Camera = game.Workspace.CurrentCamera
local MaxFOV = 70
local MinFOV = 50
local Lighting = game:GetService("Lighting")
local MaxBrightness = 2
local MinBrightness = 0.5
local Sound = workspace:WaitForChild("Sound")
local MaxPlaybackSpeed = 1
local MinPlaybackSpeed = 0.5

RunService.RenderStepped:Connect(function()
    if Character and Humanoid then
        local Distance = (Character.PrimaryPart.Position - Target.Position).Magnitude
        local Clamp = math.clamp(Distance / MaxDistance, 0, 1)
        Humanoid.WalkSpeed = MinWalkSpeed + Clamp * (MaxWalkSpeed - MinWalkSpeed)
        
        Camera.FieldOfView = MinFOV + Clamp * (MaxFOV - MinFOV)
        Lighting.Brightness = MinBrightness + Clamp * (MaxBrightness - MinBrightness)
        Sound.PlaybackSpeed = MinPlaybackSpeed + Clamp * (MaxPlaybackSpeed - MinPlaybackSpeed)
    end
end)
3 Likes

This works completely flawlessly, this is exactly what I was wanting. Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.