Is there a way that you can delay sounds in roblox i want to delay it depending on how far you are away from the sound like the speed of sound or more like a thunderstruck so if player is right next to it they will hear it fast but further away they will hear it later.
You could use player magnitude from a certain block that you want the sound to play in and just add a wait delay
Does negative time position work?
Not sure I would to script it myself to see.
I might be able to make a loop where in the beginning the max distance is 1 and over time it increases
Well max distance is how far the sound can be heard.
With the assumption that 1 Stud is equal to 0.25 meters you can determine that the speed of sound in Roblox is 1372 studs per second. Meaning for every 1372 studs a player is away from a source of a sound will determine when they hear the sound.
The best way to reproduce this would be to have the server tell each client the location of the sound and then have each client be responsible for playing that sound locally. Reason being that it would be much more complicated for the server to handle all of the timing.
I HAVE NOT TESTED THIS AND IS MOSTLY ME JUST HOPING THIS WORKS
Server-Sided Script
local ThunderEvent = --YourEventPath
local function thunderSoundEvent(Vector3Position)
ThunderEvent:FireAllClients(Vector3Position)
end
Client-Sided Script
local STUDS_PER_SECOND = 1372 --The number of studs to replicate the "speed of sound"
local function generateSound(Vector3Position)
--I ran out of time to finish this but basically create a BasePart or Attacthment at the Vector3Position
--And then play that sound.
end
local function createThunderSound(Vector3Position)
local playerDistance = game.Players.LocalPlayer.Character.HumanoidRootPart.Position - Vector3Position.magnitude --Identify how far the player is from the source
local SoundDelay = playerDistance / studsPerSecond --Determine how long the sound must be delayed at the distance the player is located
local startClockTime = os.clock()
local HighSpeedWaitConnection = game:GetService("RunService").Heartbeat:Connect(function()
local currentClockTime = os.clock()
if currentClockTime - startClockTime >= SoundDelay then
generateSound(Vector3Position)
HighSpeedWaitConnection:Disconnect()
end
end)
end