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

Why can't I locate the audio part?

So what I'm trying to do is make this audio play for everyone in the server, so I used a remove event.

I ran into this:

I'm trying to access this audio part by a variable name, using a remote event. It's says the variable 'apple', 'apple1', and 'apple2' are nil values.

--ServerScript
game.ReplicatedStorage.DanceAudio.OnServerEvent:connect(function(player, func, loc)
	if func == "Start" then
		local apple = player.Character:FindFirstChild(loc)
		apple.dancepart.SongLoop:Start()
	end
	if func == "Stop" then
		if player.Character:FindFirstChild(loc) then
			local apple1 = player.Character:FindFirstChild(loc)
			apple1.dancepart.SongLoop:Stop()
		else
			local apple2 = player.Backpack:FindFirstChild(loc)
			apple2.dancepart.SongLoop:Stop()
		end
	end
end)

My local script

--LocalScript
game.ReplicatedStorage.DanceAudio:FireServer("Start", script.Parent.Name)

Any help is appreciated!

1 answer

✓ Accepted answer

If you want to automatically play audio for everyone, then all you have to do is:

local Sound = workspace.Sound -- or where your sound is located, reccomended workspace.
local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(player) -- when the player is added to the game, not when the player resets because that is character added.
	player.CharacterAdded:connect(function(character) -- Character Has Been added!
		Sound.Playing = true
	end)
end)

If theres any problems or specifications please replay

Sincerely, lolmarkdude2

2 comments

0

bad code

0

How was this bad code?

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