script.Parent.Unequipped:Connect(function()
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("RadioUI") then
game.Players.LocalPlayer.PlayerGui.RadioUI:Destroy()
else
warn("No GUI to Destroy.")
end
local Music = script.Parent.Handle.Music
game.ReplicatedStorage.StopSoundEvent:FireServer(Music)
end)
Is that your full script? It seems odd to me you would be getting a workspace error even though I don’t see workspace written in the script anywhere.
A few things to try:
If this isn’t your full script, then wherever you have workspace written, it looks like you wrote it as Workspace. I’m pretty sure that’s deprecated, so try workspace with a lowercase w instead.
If that was your full script then I think it might be because when you equip a tool, the tool gets transferred from the backpack in the player from game.Players into the character in workspace. When you unequip, however, it goes from the character back into the backpack. You might have to change some part of your script so it refers to the backpack, not the character. In the error you have, it looks like the boombox was transferred and so when the script tried looking for it in the character, it didn’t find it. I’m not sure which part of the script it is, but I think it’s that.
If you’re still getting weird errors, and the above didn’t help, then try debugging using prints.
script.Parent.Unequipped:Connect(function()
print("Unequipped")
print(script.Parent.Name)--This tells you whether or not it's in the backpack or the actual character.
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("RadioUI") then
print("FoundRadioUI")
game.Players.LocalPlayer.PlayerGui.RadioUI:Destroy()
print("RadioDestroyed")
else
warn("No GUI to Destroy.")
end
local Music = script.Parent.Handle.Music
if Music ~= nil then
print("MusicExists")
game.ReplicatedStorage.StopSoundEvent:FireServer(Music)
end
end)
local Player = game.Players.LocalPlayer
script.Parent.Equipped:Connect(function()
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("RadioUI") then
game.Players.LocalPlayer.PlayerGui.RadioUI:Destroy()
else
warn("No GUI to Destroy.")
end
game.ReplicatedStorage.StopSoundEvent:FireServer(Player)
local RadioUI = game.Lighting.RadioUI:Clone()
RadioUI.Parent = game.Players.LocalPlayer.PlayerGui
RadioUI.Frame.TB1.PlayMuteButton.MouseButton1Click:Connect(function()
local ID = RadioUI.Frame.TL1.ID.Text
game.ReplicatedStorage.PlaySoundEvent:FireServer(ID)
end)
end)
script.Parent.Unequipped:Connect(function()
if game.Players.LocalPlayer.PlayerGui:FindFirstChild("RadioUI") then
game.Players.LocalPlayer.PlayerGui.RadioUI:Destroy()
else
warn("No GUI to Destroy.")
end
local Music = script.Parent.Handle.Music
game.ReplicatedStorage.StopSoundEvent:FireServer(Music)
end)
I will test it out with the prints.
Full server script:
game.ReplicatedStorage.PlaySoundEvent.OnServerEvent:Connect(function(Player, ID)
if tonumber(ID) then
Player.Character.BoomBox.Handle.Music.SoundId = "rbxassetid://" .. ID
Player.Character.BoomBox.Handle.Music:Play()
elseif tostring(ID) then
return
end
end)
game.ReplicatedStorage.StopSoundEvent.OnServerEvent:Connect(function(Player, Music)
Music:Stop()
end)
Alright. From what I can see, the error you’re getting is probably because the script is looking for the Music object in the player, and it thinks Music is a child of Players.dmksa123 when in fact it is a child of Players.dmksa123.Backpack.Boombox.Handle
Alright, so in the localscript where it says print(script.Parent.Name) could you do script.Parent.Parent.Name instead? I forgot to put another .Parent in there and it printed the tool name instead of the parent of the tool.