Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Create a command for change Music ?

Asked by 3 years ago

Hello, last time I made a post to fix a bug, but now I have a bigger problem, now when I create this command it allows the member with the appropriate gamepass can use this command.

However if a member uses it or I use it everything works, but the problem is that when we use another command the game thinks that we are doing just this command, the same when we speak in the game without using a command, I don't not even know why when we speak the game understands that it is a command it tries to modify the music while we do not ask since we are only talking and not using the command.

My Script :

game.Players.PlayerAdded:Connect(function(plr)
    local marketPlace = game:GetService("MarketplaceService")
    local admin = false
    local owner = false
    local canChangeMusic = false
    --local canChangeVolOfMusic = false
    --local canTP = false

    if plr.UserId == 96919359 or plr.UserId == 155674478 then
        owner = true
        admin = true
        canChangeMusic = true
        --canChangeVolOfMusic = true
        --canTP = true
    end

    if marketPlace:UserOwnsGamePassAsync(plr.userId, 11275677) then
        canChangeMusic = true
        --canChangeVolOfMusic = true
        --canTP = true
    end

    plr.Chatted:connect(function(msg)
        if string.sub((msg),1,9) == "/musicid " and admin or owner or canChangeMusic then
            local a = string.sub(msg,10)
            game.Workspace:FindFirstChild("Music").SoundId = "rbxassetid://"..a
            game.Workspace:FindFirstChild("Music").Volume = 0.1
            game.Workspace:FindFirstChild("Music").Playing = true
            game.Workspace:FindFirstChild("Music").TimePosition = 0 
        end
    end)
end)
0
Replace line 24 with "if string.sub((msg),1,9) == "/musicid " and (admin or owner or canChangeMusic) then" User#30567 0 — 3y
0
Thank you is a fix my command. Maxime66410 14 — 3y

1 answer

Log in to vote
1
Answered by
SirGamezy 186
3 years ago

You can make it like an admin command:

local SS = game:GetService("SoundService")

local adminUserIds = {
    User ID,
    User ID
}

function isAdmin(playerUserID)
    for _,item in pairs(adminUserIds) do
        if playerUserID == item then
            return true
        end
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    if isAdmin(plr.UserId) then
        plr.Chatted:Connect(function(msg)
            if string.split(msg," ")[1] == "/musicid" then
                local id = string.split(msg," ")[2]
                local sound = Instance.new("Sound",SS)
                sound.SoundId = "rbxassetid://"..(id)
                sound.Looped = true
                sound.Volume = 0.1
                sound:Play()
            end
        end)
    end
end)

With this script, when the player chats /musicid (sound id), then a sound with the desired id will play.

I am not very good with the MarketplaceService, so I suppose you can make a script that when a player buys a gamepass, their user id will be stored into the admins table.

0
I took TTChaos' answer, that settled everything, but your reasoning is also good, it also works, thank you for your help ! Maxime66410 14 — 3y
0
:D SirGamezy 186 — 3y
Ad

Answer this question