I made a script that will display a series of text on screen when a person clicks a certain block. A sound effect is supposed to play every time the text switches to a new line, but the only way I've found to successfully do this is make it so that every player can hear the sound, which isn't what I want.
local cd = script.Parent.ClickDetector
local thoughtLines = {}
cd.MouseClick:Connect(function(plr)
local playerGui = plr.PlayerGui
local gui = playerGui.ScreenGui
local textLabel = gui.TextLabel
gui.Enabled = true
thoughtLines = {"Sample1", "Sample2"}
for i,v in pairs(thoughtLines) do
-- Sound Effect executed
plr.PlayerGui.notifSpeak:Play()
textLabel.Text = (thoughtLines[i])
wait(3)
end
gui.Enabled = false
end)
If it helps, this script is in a server script.
This script also didn't seem to work in a local script:
local cd = script.Parent.ClickDetector
local SoundService = game:GetService("SoundService")
local thoughtLines = {}
local notf = Instance.new("Sound")
local function playLocalSound(soundId)
local sound = Instance.new("Sound")
sound.SoundId = soundId
SoundService:PlayLocalSound(sound)
sound.Ended:Wait()
sound:Destroy()
end
cd.MouseClick:Connect(function(plr)
local playerGui = plr.PlayerGui
local gui = playerGui.ScreenGui
local textLabel = gui.TextLabel
gui.Enabled = true
thoughtLines = {"Sample1", "Sample2"}
for i,v in pairs(thoughtLines) do
playLocalSound("rbxassetid://4590662766")
textLabel.Text = (thoughtLines[i])
wait(3)
end
gui.Enabled = false
end)

1 comment
You can put it in a local script