**Update; Me and my Developers have found a fix. **
The issue doesn’t seem to be shown, please help! The code;
local function WeldRadio(plr)
if workspace:WaitForChild(plr.Name):FindFirstChild("Radio") then workspace:WaitForChild(plr.Name):FindFirstChild("Radio") end
local Radio = game.ServerStorage.Radio:Clone()
local RadioData = require(script.Radios)
local OS = {X=0,Y=0,Z=0.8}
local RN = {X=0,Y=math.rad(180),Z=math.rad(45)}
Radio.Anchored = false
Radio.CanCollide = false
Radio.Name = "Radio"
local Weld = Instance.new("Weld",workspace[plr.Name]:WaitForChild("HumanoidRootPart"))
Weld.Part0 = workspace[plr.Name].HumanoidRootPart
Weld.Part1 = Radio
Weld.C0 = CFrame.new(OS.X,OS.Y,OS.Z) * CFrame.Angles(RN.X,RN.Y,RN.Z);
Radio.Parent = plr.Character
if Radio:FindFirstChild("Sound") then
Radio.Sound:Destroy()
end
game.ServerStorage.Sound:Clone().Parent = Radio
end
game.Players.PlayerAdded:Connect(function(plr)
local radio = Instance.new("BoolValue",plr)
radio.Name = 'radio'
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.userId,5909051) then
radio.Value = true
else
radio.Value = false
end
plr.CharacterAdded:connect(function()
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.userId,5909051) then
WeldRadio(plr)
end
end)
plr.Chatted:connect(function(msg)
if msg:lower():sub(1, 6) == '/play ' then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.userId,5909051) then
local id = msg:sub(7)
if plr.Character:FindFirstChild('Radio') then
plr.Character.Radio.Sound.SoundId = 'rbxassetid://'..id
plr.Character.Radio.Sound:Play()
end
end
end
end)
end)
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:connect(function(plr,assetId,isPurchased)
if isPurchased then
if assetId == 5909051 then
plr.radio.Value = true
WeldRadio(plr)
end
end
end)
game.ReplicatedStorage.PlaySong.OnServerEvent:connect(function(plr, id)
if plr.Character:FindFirstChild('Radio') then
plr.Character.Radio.Sound.SoundId = 'rbxassetid://'..id
plr.Character.Radio.Sound:Play()
end
end)
This is for our upcoming game, if you can help, please try to. Thanks!
Put a print in an area where the music id is changed and played. That’ll just make sure we’re actually getting to that point in the script and its not something else
Give more context other than a generic “it doesn’t work!”. Are there any errors? If so please tell the errors. Try also adding calls to print to see if your code is even executing.
Sorry, I’ve got nothing for you on this regard. You’ve said that your code is not working, but you have not provided nearly enough information for me to go off of. What exactly is the problem? Have you tried debugging this yourself by adding prints in your code? Have you checked your developer console? You need to take preliminary steps to try and debug your code first before you reach for assistance.
Please see the category guidelines before making posts. It’ll save you and those who are trying to help you quite a bit of time to get working on the problem, rather than trying to find out first what the root of it even is.
Code Review
You should validate that the return arguments of WaitForChild and/or FindFirstChild are not nil first before you try calling any methods on them.
The first expression in WeldRadio… has no real point.
Index services by GetService, not using direct dot syntax. This is both a canon way of fetching services and what should be done.
Call UserOwnsGamePassAsync once and associate the return to the player; there’s no need to call it so many times in your function
You should wrap all your code in “does player own pass?” instead of connecting whether a player owns it or not. You can update the variable somewhere else. It’d be easier on you, frankly and it’s good practice. Remember that UserOwnsGamePassAsync is a web call and it can fail - I don’t have it in my example, but you should wrap it in a pcall.
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
Players.PlayerAdded:Connect(function (plr)
local UserHasRadio = MarketplaceService:UserOwnsGamePassAsync(args_here)
local radio = Instance.new("BoolValue")
radio.Name, radio.Parent = "radio", plr
radio.Value = UserHasRadio
if UserHasRadio then
plr.CharacterAdded:Connect(function ()
WeldRadio(plr)
end)
plr.Chatted:Connect(function (message)
-- your code
end)
end
end)
^ Obviously don’t use this raw, it’s simply an example of how you can improve your current code so that you receive the benefits of both
A. Being able to potentially debug easier
B. Having a centralised, easy way to contain all your logic for those with a pass and those without
Side note (Unrelated) you’re using deprecated methods. :connect() is deprecated, :Connect() is not. It’s not gonna change anything but imo it looks better. You use a combination of :connect() and :Connect() and it’s driving me crazy.
also you use plr.userId which I’m to assume is a deprecated method or something but it should be plr.UserId (again don’t think it will change much)
Also I’m glad it’s fixed but you should’ve probably added more details to the original post. I was responding (along with many others) to add print() functions around the scripts because it seemed like you hadn’t done basic debugging and did not have very much info. “This isn’t working” isn’t very helpful.