I have a sound that enables a particle when a key is pressed, but I want to make it so it activates a sound instead, and plays the entire length of the sound instead of cutting off.
Is there any way I can transform these scripts into one that makes a sound play with a keybind?
SERVER SCRIPT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("SoundStart")
local particles = game.Workspace.Orb1
remote.OnServerEvent:Connect(function()
for number,index in pairs(particles:GetChildren()) do
if index:IsA("ParticleEmitter") then
index.Enabled = not index.Enabled
end
end
end)
CLIENT SCRIPT
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local userInputService = game:GetService("UserInputService")
local remote = ReplicatedStorage:WaitForChild("SoundStart")
userInputService.InputBegan:Connect(function(input, gp)
if gp then return end
if input.KeyCode == Enum.KeyCode.K then
remote:FireServer()
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote = ReplicatedStorage:WaitForChild("SoundStart")
local particles = workspace.Orb1
local sound = workspace -- Wherever you have your sound object in!
remote.OnServerEvent:Connect(function()
if (sound.Playing == false) then sound:Play() end -- Remove the if statement when you're not concerned with the sound being spammed.
spawn(function() -- I like to use spawn(callback) since it uses less line space. I know it's not necessarily the best practice.
for number,index in pairs(particles:GetChildren()) do
if index:IsA("ParticleEmitter") then
index.Enabled = not index.Enabled
end
end
end)
end)
First question: Yes, it should allow everyone to hear it!
Second question: You’ll likely need to grant access to use the audio via the audio’s configuration page if it isn’t considered as a Sound Effect by Roblox’s standard. As of right now, you’ll be unable to use any audio that isn’t uploaded by you and isn’t freely distributed as a sound effect.
Try using Audacity to convert it into a .ogg file, and attempt to upload the asset again! I’ve had that problem a few times myself, but converting it to an .ogg file seems to work.
If the library is ffmpeg, then there should be an official download on their official site. If all else fails, then you could try to use an online m4a => ogg converter.
Another issue though, the particles are continuous, they should just emit once. (Also counting the “EmitCount” attribute that a plugin I’m using adds)
They want it played for all players, though. The only solution would have to use remote events in order to fire to the server and play a sound for all players.