Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont this music button script play the music?

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)

5 comments

1

PUserId is not a value is it? Don't you have to put .Value?

0

mighty is right, if 'PUderId' is the actual value object you cannot concatenate it. You have to reference the 'Value' property.

0

well i got that fixed but it still wont work

0

Have you tried IsPlaying before?

0

Nope

1 answer

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.

1 comment

0

i already figured that out

This discussion is preserved as it was. New answers, comments, and votes are closed.