New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why can't I locate the audio part?

Asked by 3 months ago
Edited 3 months 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 3 months 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 BashCaster 2370 — 3mo
0
How was this bad code? MarkHasReset 76 — 3mo
Ad

Answer this question