Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't I locate the audio part?

Asked by
uhSaxlra 181
5 years ago
Edited 5 years ago

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.

01--ServerScript
02game.ReplicatedStorage.DanceAudio.OnServerEvent:connect(function(player, func, loc)
03    if func == "Start" then
04        local apple = player.Character:FindFirstChild(loc)
05        apple.dancepart.SongLoop:Start()
06    end
07    if func == "Stop" then
08        if player.Character:FindFirstChild(loc) then
09            local apple1 = player.Character:FindFirstChild(loc)
10            apple1.dancepart.SongLoop:Stop()
11        else
12            local apple2 = player.Backpack:FindFirstChild(loc)
13            apple2.dancepart.SongLoop:Stop()
14        end
15    end
16end)

My local script

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

Any help is appreciated!

1 answer

Log in to vote
0
Answered by 5 years ago

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

1local Sound = workspace.Sound -- or where your sound is located, reccomended workspace.
2local Players = game:GetService("Players")
3 
4Players.PlayerAdded:connect(function(player) -- when the player is added to the game, not when the player resets because that is character added.
5    player.CharacterAdded:connect(function(character) -- Character Has Been added!
6        Sound.Playing = true
7    end)
8end)

If theres any problems or specifications please replay

1Sincerely, lolmarkdude2
0
bad code DeceptiveCaster 3761 — 5y
0
How was this bad code? MarkHasReset 77 — 5y
Ad

Answer this question