Sorry, I thought you had a different problem.
Is it possible for you to send me a video of how it works for you? So I can check if it works in the way I mean and if yes then try to realize what’s wrong on my side.
You’re using a LocalScript and that script is parented somewhere like PlayerGui, yeah?
Sorry, I’m not on a computer at the moment to record a video.
Yes, the script is a local script, and yes, it’s inside of a GUI, therefore inside of PlayerGui.
I think there’s something else causing the issue – here’s an example place I whipped up you can try uploading and see if it works for you.
To play the boombox, equip the tool and click anywhere.
To mute / unmute boomboxes, click anywhere on the screen.
SoundTest.rbxl (48.3 KB)
Oh wait, I think I might know what’s the issue. Mine BoomBoxes have text boxes, where you can put your own ID and play any song of your desire. Therefore each of those players can play different songs, meanwhile that boombox in the testing place has already premade audio which may only be muted or unmuted (and played).
No, that wouldn’t make a difference — paste your code of when you play a song a player entered.
The code is not mine, I’m using the basic BoomBox from ToolBox. However, I’ll paste it here.
ServerScript:
--[[
Fixed by ArceusInator
--]]
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Remote = Tool:WaitForChild("Remote")
local Sound = Handle:WaitForChild("Sound")
function onUnequip()
Sound:Stop()
end
function onActivate()
Remote:FireClient(getPlayer(), "ChooseSong")
end
function getPlayer()
return game:GetService("Players"):GetPlayerFromCharacter(Tool.Parent)
end
function playSong(id)
id = id or ""
if Sound then
Sound:Destroy()
end
Sound = Instance.new'Sound'
Sound.Parent = Handle
Sound.Looped = true
Sound.PlayOnRemove = false
Sound.SoundId = "http://www.roblox.com/asset/?id="..id
Sound:Play()
end
function onRemote(player, func, ...)
if player ~= getPlayer() then return end
if func == "Activate" then
onActivate(...)
end
if func == "PlaySong" then
playSong(...)
end
end
Remote.OnServerEvent:connect(onRemote)
Tool.Unequipped:connect(onUnequip)
LocalScript:
local Tool = script.Parent
local Remote = Tool:WaitForChild("Remote")
local songgui
local CAS = game:GetService("ContextActionService")
local ActionName = "PenguinAttack"
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
function onAction()
Remote:FireServer("Activate", Mouse.Hit.p)
end
function onEquipped(mouse)
--ensure unequip
onUnequipped()
--bind
mouse.Button1Down:connect(onAction)
end
function onUnequipped()
--unbind
CAS:UnbindAction(ActionName)
if songgui then
songgui:Destroy()
end
end
function playAnimation(name, ...)
local anim = Tool:FindFirstChild(name)
if anim then
local human = Tool.Parent:FindFirstChild("Humanoid")
if human then
local track = human:LoadAnimation(anim)
track:Play(...)
end
end
end
function chooseSong()
if Player.PlayerGui:FindFirstChild("ChooseSongGui") then return end
local sg = Instance.new("ScreenGui")
sg.Name = "ChooseSongGui"
local frame = Instance.new("Frame")
frame.Style = "RobloxRound"
frame.Size = UDim2.new(0.25, 0, 0.25, 0)
frame.Position = UDim2.new((1-frame.Size.X.Scale)/2, 0, (1-frame.Size.Y.Scale)/2, 0)
frame.Parent = sg
frame.Draggable = true
local text = Instance.new("TextLabel")
text.BackgroundTransparency = 1
text.TextStrokeTransparency = 0
text.TextColor3 = Color3.new(1, 1, 1)
text.Size = UDim2.new(1, 0, 0.6, 0)
text.TextScaled = true
text.Text = "Lay down the beat!\nPut in the ID number for a song you love that's been uploaded to ROBLOX.\nLeave it blank to stop playing music."
text.Parent = frame
local input = Instance.new("TextBox")
input.BackgroundColor3 = Color3.new(0, 0, 0)
input.BackgroundTransparency = 0.5
input.BorderColor3 = Color3.new(1, 1, 1)
input.TextColor3 = Color3.new(1, 1, 1)
input.TextStrokeTransparency = 1
input.TextScaled = true
input.Text = "142376088"
input.Size = UDim2.new(1, 0, 0.2, 0)
input.Position = UDim2.new(0, 0, 0.6, 0)
input.Parent = frame
local button = Instance.new("TextButton")
button.Style = "RobloxButton"
button.Size = UDim2.new(0.75, 0, 0.2, 0)
button.Position = UDim2.new(0.125, 0, 0.8, 0)
button.TextColor3 = Color3.new(1, 1, 1)
button.TextStrokeTransparency = 0
button.Text = "Play!"
button.TextScaled = true
button.Parent = frame
button.MouseButton1Click:connect(function()
Remote:FireServer("PlaySong", tonumber(input.Text))
sg:Destroy()
end)
sg.Parent = Player.PlayerGui
songgui = sg
end
function onRemote(func, ...)
if func == "PlayAnimation" then
playAnimation(...)
end
if func == "ChooseSong" then
chooseSong()
end
end
--connect
Tool.Equipped:connect(onEquipped)
Tool.Unequipped:connect(onUnequipped)
Remote.OnClientEvent:connect(onRemote)
Change the playSong() function to this and see if it works – just make sure you put a sound instance in the handle. By it previously destroying and recreating the sound instance, it was preventing the function in my code to work since the previously-referenced instance was nil.
function playSong(id)
id = id or ""
local Sound = Handle:WaitForChild('Sound')
Sound:Stop()
Sound.Looped = true
Sound.SoundId = "http://www.roblox.com/asset/?id="..id
Sound:Play()
end
Oh yeah, that’s right. Kinda didn’t notice that and it makes sense. However what doesn’t make sense is that for some reason the sound won’t play now…
Does the handle have a sound instance in it? If not, this will yield indefinitely.
Yes, it does. Therefore I’m not really sure what’s wrong.
Have you tested again? If so, sorry, I’m out of possibilities – there must be something else going on because all I’ve given you works perfectly on my end.
Yeah, it still won’t even play the sound. I also tried the code on a Nametag system, which there it works only half way. It was meant to keep Nametags disabled (invisible) if the value was set to “false” (“Off”), but when a player joins after the button was already pressed, it makes their Nametag be visible, no matter the status, and the off button needs to be pressed again.
The a little bit updated code:
local Connections = {}
local value
local function ToggleNametags()
for i,v in ipairs(game.Players:GetPlayers()) do
local Nametag = v.Character:WaitForChild("Head"):FindFirstChild("Overhead")
if Nametag then
Nametag.Enabled = value
end
end
end
local function CreateConnection(plr)
local Nametag = plr.Character:WaitForChild("Head"):FindFirstChild("Overhead")
if not Connections[plr.Name] then
Connections[plr.Name] = {}
table.insert(Connections[plr.Name],
plr.Character:WaitForChild("Head").ChildAdded:Connect(function(object)
if object.Name == "Overhead" then
object.Enabled = value
end
end)
)
if Nametag then
table.insert(Connections[plr.Name],
value.Changed:Connect(function()
Nametag.Enabled = value
end)
)
end
end
end
script.Parent.Off.MouseButton1Click:Connect(function()
script.Parent.Status.OnOff.Text = "Off"
value = false
ToggleNametags()
end)
script.Parent.On.MouseButton1Click:Connect(function()
script.Parent.Status.OnOff.Text = "On"
value = true
ToggleNametags()
end)
game.Players.PlayerAdded:Connect(function(plr)
if not plr.Character then
repeat task.wait() until plr.Character
end
local Nametag = plr.Character:WaitForChild("Head"):FindFirstChild("Overhead")
if Nametag then
Nametag.Enabled = value
print(value)
end
CreateConnection(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
if Connections[plr.Name] then
for i,v in ipairs(Connections[plr.Name]) do
v:Disconnect()
end
Connections[plr.Name] = nil
end
end)
for i,v in ipairs(game.Players:GetPlayers()) do
CreateConnection(v)
end