How do I insert a sound into workspace using only scripts?
You would have to instance them in your game. A simple script such as this should do the trick:
local sound = Instance.new(“Sound”)
sound.SoundId = “0”
sound.Parent = game.Workspace
Edit: I will also attach this link which you can also refer to on how sound can be utilized in Roblox.
local Sound = Instance.new("Sound", workspace)
More of a simplified version than the first.
Using the 2nd argument of Instance.new is generally bad practice. Here, it isn’t particularly bad, but if you set properties of the instance, it will hurt performance for no good reason.
How will it hurt performance??
Wow ok, I’ll remember to use the first method at all times
Set the parent property last but if no other properties are being set then using the parent parameter of the instance class constructor function “Instance.new()” is fine.
function createSound(id, volume, parent) assert(id, "sound id wasn't given") id = tostring(id):gsub("%D", "") --only keeping the numbers assert(id ~= "", "sound id isn't a number") volume = volume or 0.5 --0.5 is the default volume parent = parent or workspace --workspace is the default parent local Sound = Instance.new("Sound") Sound.SoundId = "rbxassetid://"..id Sound.Volume = volume Sound.Parent = parent return Sound end local Sound = createSound("rbxassetid://1846507211") Sound.Looped = true Sound:Play()