game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local Splitted = string.split(msg," ")
if Splitted[1] == "!play" then
workspace.Sound.SoundId = Splitted[2]
workspace.Sound:Play()
end
end)
end)
If that’s the case then, I suggest to @vojta1587 that they wrap their code in pcall(). This will also prevent errors from being created if someone uses your command with invalid ids.
Even so, it means that the developer console won’t be bombarded by errors if someone decides to spam invalid IDs - in the case that they want to track an error, they could get the second returned variable of pcall when running the code.
The pcall() is absolutely redundant in this case. This is more of a Roblox issue currently as previously stated and thus sound loading cannot be fixed until the endpoint is fixed.
My hyptotesis is that it doesnt work because; since you’re loading an Audio ID from the script, the audio takes some time to load but you play it instantly after inserting the id.
Try replacing the workspace.Sound:Play()
with
task.spawn(function() -- So it doesnt yield the rest of the script
wait(workspace.Sound.IsLoaded)
workspace.Sound:Play()
end)