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 14 days ago
Edited 14 days 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 14 days 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 RobloxWhizYT 2154 — 14d
0
How was this bad code? MarkHasReset 56 — 13d
Ad

Answer this question