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
4 years ago
Edited 4 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.

--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

Log in to vote
0
Answered by 4 years ago

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
0
bad code DeceptiveCaster 3761 — 4y
0
How was this bad code? MarkHasReset 77 — 4y
Ad

Answer this question