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