Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player sounds are not found?

So I have a StarterCharacterScript, it changes the default footstep sounds which is located in a player’s character Head, it should be workspace[character].Head.Running

However, I found this unstable and glitchy, sometimes the script can find the soundtrack inside the head, but sometimes it doesn’t. All the sounds (Running, Climbing, Death) are gone, when you reset your character, there’s no “oof”, when you climb, there’s no climbing sounds etc. I tried to use WaitForChild, or even repeat wait() until character, however when I try to debug with the developer console with the command

print (workspace.Headstackk.Head.Running.Volume)

It resulted an error, I’m wondering what caused this bug, and I don’t think other scripts in my game affected it.

This only happen in game, it doesn’t happen in Roblox Studio, even though there’s accurate singleplay.

1 comment

0

Provide your actual code.

1 answer

This was mine a while back when I was testing sounds out so this may not work, Also put it in StarterCharecterScripts

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local SOUND_EVENT_FOLDER_NAME = "DefaultSoundEvents"
local DEFAULT_SERVER_SOUND_EVENT_NAME = "DefaultServerSoundEvent"

local SoundEventFolder = ReplicatedStorage:FindFirstChild(SOUND_EVENT_FOLDER_NAME)
local DefaultServerSoundEvent = nil

local useSoundDispatcher = UserSettings():IsUserFeatureEnabled("UserUseSoundDispatcher")
if useSoundDispatcher then
	if not SoundEventFolder then
		SoundEventFolder = Instance.new("Folder")
		SoundEventFolder.Name = SOUND_EVENT_FOLDER_NAME
		SoundEventFolder.Archivable = false
		SoundEventFolder.Parent = ReplicatedStorage
	end

	DefaultServerSoundEvent = SoundEventFolder:FindFirstChild(DEFAULT_SERVER_SOUND_EVENT_NAME)
else
	DefaultServerSoundEvent = ReplicatedStorage:FindFirstChild(DEFAULT_SERVER_SOUND_EVENT_NAME)
end

if not DefaultServerSoundEvent then
	if useSoundDispatcher then
		DefaultServerSoundEvent = Instance.new("RemoteEvent", SoundEventFolder)
	else
		DefaultServerSoundEvent = Instance.new("RemoteEvent", ReplicatedStorage)
	end

	DefaultServerSoundEvent.Name = DEFAULT_SERVER_SOUND_EVENT_NAME
	DefaultServerSoundEvent.OnServerEvent:Connect(function() end)
end

local function CreateNewSound(name, id, looped, pitch, parent)
	local sound = Instance.new("Sound")
	sound.SoundId = id
	sound.Name = name
	sound.archivable = false
	sound.Pitch = pitch
	sound.Looped = looped
	sound.MinDistance = 5
	sound.MaxDistance = 150
	sound.Volume = 0.65
	sound.Parent = parent

	if DefaultServerSoundEvent then
		local CharacterSoundEvent = Instance.new("RemoteEvent", sound)
		CharacterSoundEvent.Name = "CharacterSoundEvent"
		CharacterSoundEvent.OnServerEvent:Connect(function(player, playing, resetPosition)
			if type(playing) ~= "boolean" then
				return
			end
			if type(resetPosition) ~= "boolean" then
				return
			end

			if player.Character ~= script.Parent then
				return
			end
			for _, p in pairs(Players:GetPlayers()) do
				if p ~= player then
					
					if useSoundDispatcher then
						SoundEventFolder:FindFirstChild("SoundDispatcher"):Fire(p, sound, playing, resetPosition)
					else
						DefaultServerSoundEvent:FireClient(p, sound, playing, resetPosition)
					end
				end
			end
		end)
	end
	return sound
end

local head = script.Parent:FindFirstChild("Head")
if not head then
	error("Head")
	return
end

CreateNewSound("GettingUp", "rbxasset://sounds/action_get_up.mp3", false, 1, head)
CreateNewSound("Died", "rbxasset://sounds/uuhhh.mp3", false, 1, head) 
CreateNewSound("FreeFalling", "rbxasset://sounds/action_falling.mp3", true, 1, head)
CreateNewSound("Jumping", "rbxasset://sounds/action_jump.mp3", false, 1, head)
CreateNewSound("Landing", "rbxasset://sounds/action_jump_land.mp3", false, 1, head)
CreateNewSound("Splash", "rbxasset://sounds/impact_water.mp3", false, 1, head)
CreateNewSound("Running", "rbxasset://sounds/action_footsteps_plastic.mp3", true, 1.85, head)
CreateNewSound("Swimming", "rbxasset://sounds/action_swim.mp3", true, 1.6, head)
CreateNewSound("Climbing", "rbxasset://sounds/action_footsteps_plastic.mp3", true, 1, head)

2 comments

0

Please give an explanation and not just a script you wrote in the past.

0

Thanks! Seems that the problem is resolved.

This discussion is preserved as it was. New answers, comments, and votes are closed.