Hello, so I got an idea, for one of my games. Basically, if your camera is inside of a moving region, it changes the sound in a part.
I looked on google, and couldn’t find a stable solution.
Any help is appreciated.
Thanks,
Gedeon
Hello, so I got an idea, for one of my games. Basically, if your camera is inside of a moving region, it changes the sound in a part.
I looked on google, and couldn’t find a stable solution.
Any help is appreciated.
Thanks,
Gedeon
local Run = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local OldCFrame = CFrame.new(0, 0, 0)
local Part = Instance.new("Part")
Part.Anchored = true
Part.CFrame = OldCFrame
Part.Parent = workspace
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://0" --Change 0 to ID of audio.
Sound.Parent = script
Camera.CameraSubject = Part
Run.RenderStepped:Connect(function()
local NewCFrame = Part.CFrame
if NewCFrame ~= OldCFrame then --Checks if part moved in last frame.
if not Sound.IsPlaying then --Checks if the sound is already playing.
Sound:Play() --Plays sound if it is not already playing.
end
OldCFrame = NewCFrame
else --Checks if part did not move in the last frame.
if Sound.IsPlaying then --Checks if sound is playing.
Sound:Stop() --Stops sound if it is playing.
end
end
end)
Just a bare-bones script but this is essentially what you’re looking for.
Hello thanks for the help, but as I stated, the region moves (its on a vehicle), and also there will be multiple of them (which need to do same thing). Do you have any idea on how to make that?