basically, math.clamp with a maxDistance variable and your current magnitude:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local sound = workspace.Main["around the clock glovey theme"]
local runService = game:GetService("RunService")
local MagnitudePart = workspace.Main
runService.RenderStepped:Connect(function()
local magnitude = (MagnitudePart.Position - character.Head.Position).Magnitude
-- this is where the math.clamp should be---sound.PlaybackSpeed = 10 / (MagnitudePart.Position - character.Head.Position).Magnitude --math.clamp(50, .5, 2)
if magnitude <=40 then
if not sound.Playing then
print("playing")
sound:Play()
end
elseif magnitude > 40 then
if sound.Playing then
print("not playing")
sound:Stop()
end
end
end)
yeah, math.clamp does require 3 values and no if your talking about the RollOff.
im guessing this: math.Clamp(magnitude, lowest playback speed, highest playback speed)
Well you may need to set the PlaybackSpeed limits (Both Min and Max) so that it’ll return back the value you want it to stop at
Maybe something like this?
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local sound = workspace.Main["around the clock glovey theme"]
local runService = game:GetService("RunService")
local MagnitudePart = workspace.Main
runService.RenderStepped:Connect(function()
local magnitude = (MagnitudePart.Position - character.Head.Position).Magnitude
--New stuff--
local MinPitch = 0.25
local MaxPitch = 2
local DistanceLimiter = magnitude / 10
sound.PlaybackSpeed = math.clamp(DistanceLimiter, MinPitch, MaxPitch) --This will return back the MinPitch, Range, or the MaxPitch depending on what the Magnitude is
if magnitude <=40 and not sound.Playing then
print("playing")
sound:Play()
elseif magnitude > 40 and sound.Playing then
print("not playing")
sound:Stop()
end
end)
This is just my assumption and guess on how you could use math.clamp
it works! yay math.clamp! but, (i swear i say this in every topic of mine) its opposite; the sound get slower the closer you are, when it should get faster the closer
on the side, could you give me a brief explanation on how distance limiter works?
The DistanceLimiter prevents the magnitude from exceeding a huge number relevant to the pitch you’re wanting to play, which is why we divide it by 10 but it seems as though I mixed up
Try this:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local sound = workspace.Main["around the clock glovey theme"]
local runService = game:GetService("RunService")
local MagnitudePart = workspace.Main
runService.RenderStepped:Connect(function()
local magnitude = (MagnitudePart.Position - character.Head.Position).Magnitude
--New stuff--
local MinPitch = 0.25
local MaxPitch = 2
local DistanceLimiter = 10 / magnitude
sound.PlaybackSpeed = math.clamp(DistanceLimiter, MinPitch, MaxPitch) --This will return back the MinPitch, Range, or the MaxPitch depending on what the Magnitude is
if magnitude <=40 and not sound.Playing then
print("playing")
sound:Play()
elseif magnitude > 40 and sound.Playing then
print("not playing")
sound:Stop()
end
end)