Why doesnt this work?:
local Players = game:GetService("Players") local name = "yourfuturepilot2" Players.OnPlayerAdded:Connect(function(player) print("yes") local audio = player.PlayerScripts.audio if player.Name == name then audio:Play() print("audio has played for player") end end)
It is in a local script in starterplayerscripts, and the audio is in the same place. Nothing is showing up in output, unfortunately. this is supposed to play music for someone with a specific name that enters the game. I know I am probably just being an idiot, but I am a beginner so just go easy on me.
You said resolved but if you want the audio to play for everyone you should change your code back to:
local Players = game:GetService("Players") local name = "yourfuturepilot2" Players.PlayerAdded:Connect(function(player) print("yes") local audio = player.PlayerScripts.audio if player.Name == name then audio:Play() print("audio has played for player") end end)
The problem was you had OnPlayerAdded
when it's really just PlayerAdded
. This script will make the audio play for everyone instead of just yourself.
RESOLVED I changed it to
local audio = game.Players.LocalPlayer.PlayerScripts.Audio if game.Players.LocalPlayer.Name == "yourfuturepilot2" then -- players name here audio:Play() print("audio has played for player") end
You cannoy use the PlayerAdded
event as this is a local script. To get the local player, it should looks something like this:
local Players = game:GetService("Players") local player = Players.LocalPlayer local chosenID = 125293735 local audio = player.PlayerScripts.Audio if player.UserId == chosenID then audio:Play() print("Audio played for " .. player.Name .. " - " .. player.UserId) end
Also, do not store your audio in any location that is for scripts. You can store it in SoundService or in a model. NEVER use a player name. Use player.UserId instead. A player can always change their name, but not their ID!