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

Why wont this music button script play the music?

Asked by 8 years ago

I have been trying for a couple hours to do this and it just wont work at all

one error occurred that says: Players.TheGrimDeathZombie.PlayerGui.MainMenu.Options.OptionsFrame.Main:2: attempt to concatenate field 'PUserId' (a userdata value)

the script is here:

local PrefMusicStore = game:GetService('DataStoreService'):GetDataStore('PrefferedMusic')
local PrefMusic = PrefMusicStore:GetAsync('User_'..script.Parent.PUserId)
if PrefMusic == nil then
    PrefMusicStore:SetAsync('User_'..script.Parent.PUserId, "Creative6")
    script.Parent.Parent.Parent.Creative6:Play()
else
    script.Parent.Parent.Parent:FindFirstChild(PrefMusic):Play()
end

script.Parent.M1.MouseButton1Click:connect(function()
    local Items = script.Parent.Parent.Parent:GetChildren()
    for index, value in ipairs(Items) do
        if value:IsA('Sound') then
            value:Stop()
        end
    end
    wait(.1)
    script.Parent.Parent.Parent.Creative6:Play()
    PrefMusicStore:SetAsync('User_'..script.Parent.PUserId, "Creative6")
end)

script.Parent.M1.MouseButton1Click:connect(function()
    local Items = script.Parent.Parent.Parent:GetChildren()
    for index, value in ipairs(Items) do
        if value:IsA('Sound') then
            value:Stop()
        end
    end
    wait(.1)
    script.Parent.Parent.Parent.Damage:Play()
    PrefMusicStore:SetAsync('User_'..script.Parent.PUserId, "Damage")
end)
1
PUserId is not a value is it? Don't you have to put .Value? mightydifferent 85 — 8y
0
mighty is right, if 'PUderId' is the actual value object you cannot concatenate it. You have to reference the 'Value' property. Goulstem 8144 — 8y
0
well i got that fixed but it still wont work Thegrimdeathzombie 40 — 7y
0
Have you tried IsPlaying before? LearnBeginnersLua -2 — 7y
0
Nope Thegrimdeathzombie 40 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Provided that your P_UserId is a Value type, then you will need to use script.Parent.PUserId.Value. This is because script.Parent.PUserId is just a container for PUserId.Value, so if you want to concatenate a string with it, you will need to use the .Value.

0
i already figured that out Thegrimdeathzombie 40 — 7y
Ad

Answer this question