Hello so I have this script for a boombox, and the script is suppose to make when you put in the music id it will play that song, but it seems to only play for the player and not for everybody, here is the server and client script
SERVER SCRIPT
game.Players.PlayerAdded:Connect(function(LocalPlayer)
LocalPlayer.PlayerGui:WaitForChild("BoomBoxGui").Frame.TextButton.MouseButton1Click:Connect(function()
local Humanoid = LocalPlayer.Character:WaitForChild("Humanoid")
local Character = LocalPlayer.Character
local Sound = Character:FindFirstChild("BoomBox").Sound
Sound:Play()
game.ReplicatedStorage.BoomBox:FireAllClients()
end)
end)
LOCAL SCRIPT
game.ReplicatedStorage.BoomBox.OnClientEvent:Connect(function()
local Character = game.Players.LocalPlayer.Character
local Text = script.Parent.Parent.TextBox.Text
Character:FindFirstChild("BoomBox").Sound.SoundId = "rbxassetid://"..Text
local Name = game:GetService("MarketplaceService"):GetProductInfo(Text).Name
script.Parent.Parent.NameId.Text = Name
end)
local Humanoid = LocalPlayer.Character:WaitForChild("Humanoid")
local Character = LocalPlayer.Character
local Sound = Character:FindFirstChild("BoomBox").Sound
Sound:Play()
You would probably have to send the “playing” player through the remote event. As of right now youre using the local player of each receiving end, which is the likely source of your problem
OnServerEvent:Connect(function()
for _, player in pairs (game.Players:GetPlayers()) do
local Character = player.Character
local Text = --script.Parent.Parent.TextBox.Text whatever the location that the server can get to idk
Character:FindFirstChild("BoomBox").Sound.SoundId = "rbxassetid://"..Text
local Name = game:GetService("MarketplaceService"):GetProductInfo(Text).Name
script.Parent.Parent.NameId.Text = Name
end
end)
Actually this doesn’t make sense considering its already being done via server.
Perhaps remove the fire clients and insert the get players for loop.
Fair enough- but my point still stands. This is not a good way to handle this code afaik, I imagine Client->Server & Sanity Checks -> All Clients makes much more sense. Otherwise, the problem with your code could be that it lacks necessary checks (is the boombox equipped? if not it will not exist inside of character).
Because this test works totally fine; the problem lies outside of your code structure. It could also be the inconsistent pathways which may or may not act how you expect them to.
Server:
game.Players.PlayerAdded:Connect(function(LocalPlayer)
LocalPlayer.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("ImageButton").MouseButton1Click:Connect(function()
local Humanoid = LocalPlayer.Character:WaitForChild("Humanoid")
local Character = LocalPlayer.Character
game.ReplicatedStorage.BoomBox:FireAllClients()
end)
end)
Client:
game.ReplicatedStorage.BoomBox.OnClientEvent:Connect(function()
local Character = game.Players.LocalPlayer.Character
print('i got it!')
end)