I’m working a music script for my game Alan’s Fan Club. I’ve already made the system. But here, I could make it so I have to put name by my own inside the script "DJs = " in order to be able to skip music. But I want it so players who owns a specific gamepass can skip music.
My script:
local songs = {
[3144033802] = "Alan Walker - Lily",
[279207008] = "Alan Walker - The Spectre",
[279206904] = "Alan Walker - Fade",
[2454470726] = "Alan Walker - Alone",
[1473603054] = "Alan Walker - Sing me to sleep (REMIX)",
}
DJs = {"Techyfied", "someone"}
mutebutton = true
notifyGui = true
local arr = {}
for k in pairs(songs) do
table.insert(arr, k)
end
local music = script.Parent.Sound
function play()
local key = arr[math.random(#arr)]
music.SoundId = "rbxassetid://"..key
music:Play()
script.Parent.CurrentSong.Value = songs[key]
game.StarterGui.MusicPlayer.Mainframe.MusicName.Text = script.Parent.CurrentSong.Value
music.Ended:wait(0.5)
music.TimePosition = 0
end
script.Parent.skip.OnServerEvent:Connect(function(player)
for i in pairs(DJs) do
if DJs[i] == player.Name then
play()
else
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if mutebutton then
local gui = script.Mute:Clone()
gui.Parent = player.PlayerGui
end
if notifyGui then
local gui = script.SongNotif:Clone()
gui.Parent = player.PlayerGui
end
for i in pairs(DJs) do
if DJs[i] == player.Name then
print(player.Name.."Is a DJ")
local skip = script.Skip:Clone()
skip.Parent = player.PlayerGui
else
-- not a DJ
end
wait()
end
end)
end)
while true do
play()
end
Here, the line - DJs = {"Techyfied", "someone"}
makes people DJ and players can skip. I want it so it automatically detect player name if they own a gamepass, and add them to DJs list when they join so they can skip music.
local songs = {
[3144033802] = "Alan Walker - Lily",
[279207008] = "Alan Walker - The Spectre",
[279206904] = "Alan Walker - Fade",
[2454470726] = "Alan Walker - Alone",
[1473603054] = "Alan Walker - Sing me to sleep (REMIX)",
}
DJs = {"Techyfied", "someone"}
if game:GetService(“MarketplaceService”):UserOwnsGamePaasAsync(Player.UserId, GamepassId) then
table.insert(DJs, Player.Name)
end
mutebutton = true
notifyGui = true
local arr = {}
for k in pairs(songs) do
table.insert(arr, k)
end
local music = script.Parent.Sound
function play()
local key = arr[math.random(#arr)]
music.SoundId = "rbxassetid://"..key
music:Play()
script.Parent.CurrentSong.Value = songs[key]
game.StarterGui.MusicPlayer.Mainframe.MusicName.Text = script.Parent.CurrentSong.Value
music.Ended:wait(0.5)
music.TimePosition = 0
end
script.Parent.skip.OnServerEvent:Connect(function(player)
for i in pairs(DJs) do
if DJs[i] == player.Name then
play()
else
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if mutebutton then
local gui = script.Mute:Clone()
gui.Parent = player.PlayerGui
end
if notifyGui then
local gui = script.SongNotif:Clone()
gui.Parent = player.PlayerGui
end
for i in pairs(DJs) do
if DJs[i] == player.Name then
print(player.Name.."Is a DJ")
local skip = script.Skip:Clone()
skip.Parent = player.PlayerGui
else
-- not a DJ
end
wait()
end
end)
end)
while true do
play()
end
Try do folder in ServerStorage named “DJ’s”
Then do another script and in this script do
game.Players.PlayerAdded:Connect(funtion(Player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.UserId, GamepassId) then
local Value = instance.new("StringValue",game.ServerStorage["DJ's"])
Value.Name = Player.Name
end)
How to check if player is Dj simple
if game.ServerStorage["DJ's"]:FindFirstChild(Player.Name) then
print(Player.Name.." Is DJ")
end
You need a players added event and have the UserOwnsGamePassAsync like a if statement in the event. If true the user has the gamepass and you can use player as in the player added event and do player.Name
You’re trying to force one solution when there’s a better approach to the problem. You do not need to force a player’s name to be in the DJs table, simply check if they are in that table or if they own the game pass (the name check will come first, the game pass one afterward).
I don’t know how you’re checking from the DJs list but if you’re using a loop, opt to use table.find instead. Using that as a condition in your if statement will check if table.find returns a truthy value and do whatever you need to do, or stop the code there if not.
Do not copy paste my code and say it doesn’t work when you try, because this isn’t a complete code sample. You’re expected to fill the missing pieces or change things yourself and debug issues.
From your skip RemoteEvent:
function(player)
if table.find(DJs, player.Name) or MarketplaceService:UserOwnsGamePassAsync(player.UserId, 0) then
play()
end
end
Same goes with your Skip Gui. Only change: don’t leave a dangling else, not necessary.
if table.find(DJs, player.Name) or MarketplaceService:UserOwnsGamePassAsync(player.UserId, 0) then
print(player.Name, "is a DJ")
local skip = script.Skip:Clone()
skip.Parent = player.PlayerGui
end