[do not answer here, post moved]

How to adjust the distance of a sound with “rolloffmaxdistance”?

I have a push player system by typing E, a sound is played and the player is pushed.

My sound is placed in “Workspace” because I want it to be heard by everyone but only at a certain distance and the sound it is triggered using a modulescript in ServerScriptService.

The problem is that the sound is global and no max distance is applied despite the settings.

Do you have a solution ? Thank you.

Here is the moduleScript placed in SeverScriptService:

local sound = workspace.Sound
local module = {}

local DebriService = game:GetService('Debris')


local TKPushData = {
	DebounceTime = 1,
	Debounce = {},
	Victims = {},
}


function CheckDebounce(Character,Target)
	local CanAttackVictim = true 
	local CanAttack = false 
	
	if not TKPushData['Debounce'][Character] then 
		TKPushData['Debounce'][Character] = {
			Last = tick()+TKPushData['DebounceTime']
		}
		CanAttack = true 
	end
	
	if TKPushData['Debounce'][Character] then 
		if tick() - TKPushData['Debounce'][Character]['Last'] >= TKPushData['DebounceTime'] then 
			CanAttack = true 
		else 
			CanAttack = false 
		end
	end
	
	if  TKPushData[table.find(TKPushData['Victims'],Target)] then
		CanAttackVictim = false
	end
	
	if CanAttack==true and CanAttackVictim==true then 
		return true 
	end
		
		--Targets[table.find(Targets, Target)]

end

module.TelekineticPush = function(Character,Target,CameraVector)
	local HRP = Character.HumanoidRootPart 
	
	local THRP = Target.HumanoidRootPart 
	local TRagdoll = Target.Ragdoll
	
	if CheckDebounce(Character,Target) == true then 
		TKPushData['Debounce'][Character] = {Last = tick()}
		local Force = Instance.new('LinearVelocity')
		TRagdoll.Value += 2
		local Force = Instance.new("BodyVelocity")
		Force.MaxForce = Vector3.new(30000,math.huge,30000)
		Force.P = math.huge
		Force.Velocity = Vector3.new(45,0,45) *CameraVector
		Force.Velocity += Vector3.new(0,5,0)
		Force.Parent = THRP 
		DebriService:AddItem(Force,.3)
		
		
		local Animation = Instance.new('Animation')
		Animation.AnimationId = 'rbxassetid://'
		local Track = Character.Humanoid.Animator:LoadAnimation(Animation)
		Track:Play()
		sound:Play()
		sound.RollOffMaxDistance = 10

		
		
		
		wait(TKPushData['DebounceTime'])
		for _, v in pairs(TKPushData['Victims']) do 
			if v == Target then 
				table.remove(TKPushData['Victims'],v)
			end
		end
	end
	
	
	
end







return module

A global sound doesn’t have a rolloffdistance. Being global means it’s everywhere at the same volume.

So you should probably make the sound come from the player that’s being pushed.
Then you can make the maxrolloffdistance extremely high from the player, then players will hear it that far away, but just quieter as they are farther away. If your game is only 2000 studs across then make the maxrolloffdistance 2900 studs (the diagonal distance of a 2000x2000 stud square or whatever number that works for you.

thanks for the answer, how can i do this? do you have an example? I’m really not good at scripting. :sweat_smile:

All you have to do is insert a sound into the player’s character that is being pushed. From here, you just change the sound properties.

local Sound = Instance.new(“Sound”, game.Workspace.Part) - Set the sound’s parent to a player though, not this example -

Sound.MaxRollOffDistance = 2900 - In studs -
Sound.SoundId = “rbxassetid://1234” - Your sound id here -

Sound.IsPlaying = true
Sound:Play()

From what I know, this example should work correctly.

Hope this helps :slight_smile:

1 Like

It does not work, what do you mean by

?

When the player is pushed, you want to make the sound play from their character, so just create the sound there, inside the character’s humanoidrootpart