I’ve been trying to to play a sound locally, can’t seem to figure it out. Have it in a local script in ServerScriptService. Thanks!
Here’s my code:
local SoundService = game:GetService("SoundService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local adventure = game.ReplicatedStorage:WaitForChild("Adventure")
local debounce = false
local function Sound(player)
if not debounce then
debounce = true
adventure:FireClient(player)
local sound = Instance.new("Sound")
sound.Name = "Adventure"
sound.SoundId = "rbxassetid://143562367"
sound.Parent = workspace
sound:Play()
wait(1)
sound.Ended:Wait()
debounce = false
end
end
game.Workspace.Portals.Portal1.ToS1.Touched:Connect(Sound)
Roblox has an api just for this, SoundService:PlayLocalSound
Didn’t work.
local SoundService = game:GetService("SoundService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local adventure = game.ReplicatedStorage:WaitForChild("Adventure")
local debounce = false
local function Sound()
if not debounce then
debounce = true
local sound = Instance.new("Sound")
sound.Name = "Adventure"
sound.SoundId = "rbxassetid://143562367"
sound.Parent = workspace
SoundService:PlayLocalSound(sound)
wait(1)
sound.Ended:Wait()
debounce = false
end
end
game.Workspace.Portals.Portal1.ToS1.Touched:Connect(Sound)
I missed this part the first time. LocalScripts don’t work in ServerScriptService. Instead, put it in StarterPlayer > StarterCharacterScripts
Put it in there, the sound plays but it plays for both players.
local SoundService = game:GetService("SoundService")
local function playLocalSound(soundId)
-- Create a sound
local sound = Instance.new("Sound")
sound.SoundId = soundId
-- Play the sound locally
SoundService:PlayLocalSound(sound)
end
local function onNewScriptButtonClicked()
-- Create new empty script
local newScript = Instance.new("Script")
newScript.Parent = game:GetService("ServerScriptService")
-- Call function to play local sound
playLocalSound("rbxassetid://164502630") -- Insert audio asset ID here
end
-- Connect plugin button to action function
game.Workspace.Portals.Portal1.ToS1.Touched:Connect(onNewScriptButtonClicked)