The problem is when the player dies the character get removed and the audio too so I have to do like one “save” for keep playing the audio again. basicly is if the player respawn the audio ID will be the old audio ID
I tried to find out how I could do that but I didnt fine yet.
the scripts looks like this:
--Local script
local player = game.Players.LocalPlayer
local MS = game:GetService("MarketplaceService")
local RS = game.ReplicatedStorage
local bin = script.Parent
local clicked = false
local RadioframeOn = false
local isRadioGamepass = false
local id = 21914253
if MS:UserOwnsGamePassAsync(player.UserId,id) then
isRadioGamepass = true
end
MS.PromptGamePassPurchaseFinished:Connect(function(plr,gamePassId,wasPurchased)
if plr.Name == player.Name and gamePassId == id and wasPurchased then
isRadioGamepass = true
bin.RadioFrame.Visible = true
RS.RadioEvent:FireServer("GiveRadio")
end
end)
bin.RadioButton.MouseButton1Click:Connect(function()
if isRadioGamepass then
if RadioframeOn == false then
RadioframeOn = true
bin.RadioFrame.Visible = true
else
RadioframeOn = false
bin.RadioFrame.Visible = false
end
else
MS:PromptGamePassPurchase(player,id)
end
end)
bin.RadioFrame.Play.MouseButton1Click:Connect(function()
if not clicked then
if isRadioGamepass then
if tonumber(bin.RadioFrame.Input.Text) then
if MS:GetProductInfo(bin.RadioFrame.Input.Text).AssetTypeId == 3 then
bin.RadioFrame.Title.Text = MS:GetProductInfo(bin.RadioFrame.Input.Text).Name
RS.RadioEvent:FireServer("PlaySong",bin.RadioFrame.Input.Text)
else
clicked = true
bin.RadioFrame.Input.Text = ""
bin.RadioFrame.Input.PlaceholderText = "Song ID"
wait(3)
clicked = false
bin.RadioFrame.Input.PlaceholderText = "Song ID"
end
else
clicked = true
bin.RadioFrame.Input.Text = ""
bin.RadioFrame.Input.PlaceholderText = "Song ID"
wait(3)
clicked = false
bin.RadioFrame.Input.PlaceholderText = "Song ID"
end
end
end
end)
bin.RadioFrame.Stop.MouseButton1Click:Connect(function()
if isRadioGamepass then
bin.RadioFrame.Title.Text = ""
RS.RadioEvent:FireServer("StopSong")
end
end)
--ServerScriptService
local MS = game:GetService("MarketplaceService")
local id = 21914253
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if MS:UserOwnsGamePassAsync(player.UserId,id) then
local clone = game.ServerStorage.Radio:Clone()
clone.Parent = character
end
end)
end)
game.ReplicatedStorage.RadioEvent.OnServerEvent:Connect(function(player,...)
local tuple = {...}
local arg1 = tuple[1]
local arg2 = tuple[2]
if arg1 == "PlaySong" then
game.Players.PlayerAdded:Connect(function(plr)
local Respawns = -1
plr.CharacterAdded:Connect(function(char)
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. arg2
radio:FindFirstChild("Handle").Sound:Play()
end
end)
end)
elseif arg1 == "StopSong" then
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound:Stop()
end
elseif arg1 == "GiveRadio" then
local clone = game.ServerStorage.Radio:Clone()
local character = player.Character
clone.Parent = character
end
end)
if arg1 == "PlaySong" then
game.Players.PlayerAdded:Connect(function(plr)
local Respawns = -1
plr.CharacterAdded:Connect(function(char)
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. arg2
radio:FindFirstChild("Handle").Sound:Play()
end
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
local currentid = arg2
plr.CharacterAdded:Connect(function(char)
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. currentid
radio:FindFirstChild("Handle").Sound:Play()
end
end)
end)
the radio is inside the character and the audio is inside the radio
like this
but when the player dies the character get removed and the audio too so I have to find one way for play it again without past the ID on the GUI and click “play” (I dont know if I can put the TimePosition again)
--add a value that player enabled radio
--add the next value to "GiveRadio" function
local enabledrad = Instance.new("BoolValue",player)
enabledrad.Name = "GotRadio"
game.Players.PlayerAdded:Connect(function(plr)
local currentid = arg2
local timeposition = 0
plr.CharacterAdded:Connect(function(character)
local radio = character:FindFirstChild("Radio")
spawn(function()
while wait(0.1) and radio do
if radio:FindFirstChild("Handle"):FindFirstChild("Sound") then
timeposition = radio:FindFirstChild("Handle"):FindFirstChild("Sound").TimePosition
end
end
end)
if player:FindFirstChild("GotRadio") and not radio then
local clone = game.ServerStorage.Radio:Clone()
clone.Parent = character
radio = clone
end
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. currentid
radio:FindFirstChild("Handle").Sound.TimePosition = timeposition
radio:FindFirstChild("Handle").Sound:Play()
end
end)
end)
local MS = game:GetService("MarketplaceService")
local id = 21914253
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if MS:UserOwnsGamePassAsync(player.UserId,id) then
local clone = game.ServerStorage.Radio:Clone()
clone.Parent = character
end
end)
end)
game.ReplicatedStorage.RadioEvent.OnServerEvent:Connect(function(player,...)
local tuple = {...}
local arg1 = tuple[1]
local arg2 = tuple[2]
if arg1 == "PlaySong" then
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. arg2
radio:FindFirstChild("Handle").Sound:Play()
end
elseif arg1 == "StopSong" then
local character = player.Character
local radio = character:FindFirstChild("Radio")
if radio then
radio:FindFirstChild("Handle").Sound:Stop()
end
elseif arg1 == "GiveRadio" then
local enabledrad = Instance.new("BoolValue",player)
enabledrad.Name = "GotRadio"
game.Players.PlayerAdded:Connect(function(plr)
local currentid = arg2
local timeposition = 0
plr.CharacterAdded:Connect(function(character)
local radio = character:FindFirstChild("Radio")
spawn(function()
while wait(0.1) and radio do
if radio:FindFirstChild("Handle"):FindFirstChild("Sound") then
timeposition = radio:FindFirstChild("Handle"):FindFirstChild("Sound").TimePosition
end
end
end)
if player:FindFirstChild("GotRadio") and not radio then
local clone = game.ServerStorage.Radio:Clone()
clone.Parent = character
radio = clone
end
if radio then
radio:FindFirstChild("Handle").Sound.SoundId = "rbxassetid://" .. currentid
radio:FindFirstChild("Handle").Sound.TimePosition = timeposition
radio:FindFirstChild("Handle").Sound:Play()
end
end)
end)
local clone = game.ServerStorage.Radio:Clone()
local character = player.Character
clone.Parent = character
end
end)
it supposed to be INSIDE the player in the game.Players.[player] not in the characters and you put everything really wrongly also other stuff should change the old stuff in the PlaySong i dont got time ill go
I highly apologize for not getting back to that post that you made a little while back.
You’re going about doing this the wrong way.
What I would advise doing is reading up on Humanoid, and one of it’s functions.
As you may know from reading it, there is a function called Humanoid.Died, which can be heavily utilized here.
This can work with pretty much any local, or server script, but I personally recommend server because the server can check if the ID exists within in the Sound object, and determine where to temporarily move it.
As you can infer, I’m saying that you should probably make it temporarily move the audio somewhere else, and back on the character when they respawn.
You could also make a check on the server, maybe under the Player object of the given player so if it’s true or not you can tell the server to move back any audio that they owned. You could label the audio with the players username then index by that to move the Parent back to the radio.
This is all hypothetical though, and today’s my first day of school so I don’t got much time to script this entire system just to help you. Maybe later, no promises.
But I dont understand how I can make this I can do humanoid.Died yes and clone one value into the player for play the ID again but I dont know how I can make the same ID and timePosition