Hey guys I know this issues been covered but please hear me out as nothing ive seen suggested works.
Background: Im making a game with portals. Each portal sends you to a different world(same server though no external teleport). Each world has its own music.
The problem: i want it to be multiplayer but I cant because anytime a song plays that should be for you locally, everyone hears it. Ive tried writing the code in localscripts that go into the parts themselves, and also localscripts into startplayer, startergui, ect. Everyones music still jumbles on top of eachother. I tried using omclient remote events, didnt work.
I learned from roblox documentation of a feature called “PlayLocalSound()” it claims sounds cannot be client based without this (idk of thats true or not). I tried it, still didnt work, the sounds are heard by the entire server. So im not sure what to do. Is this a roblox issue? Or am I missing something?
Please dont answer with sarcastic or rude comments I just want help and I did try hard to look for an answer before posting this.
So I’m guessing you got a folder or something in workspace with all different musics in it. You are using a localscript to play the right one, and everyone else hears it as well?
I have it so that once you enter a particular world, in that script that takes you to the world, the song is also set to play and once you leave, i have it so it stops
I have it so when you join you just hear wind, thats working fine no other music. When you join a world, its respective music plays as well like it should. Its just everyone hears it and songs get jumbled together if other people join diff worlds
Ikr thats what im saying it just defies logic lol. But yeah i have my brother test it with me and anytime I tried things wed still hear eachothers music cross over eachother. Idk what to do
I think PlayLocalSound() is meant more for Studio plugins to be able to play sound in the editor, not really for game use.
If you’re relying on touched events, make sure otherPart from the Touched event belongs to the local player. You can do it like this:
local Players = game:GetService("Players")
local part = (reference the part here)
local function onTouched(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)
if player and player == Players.LocalPlayer then
-- put your code here
end
end
part.Touched:Connect(onTouched)
By the way, LocalScripts only run in specific places. They don’t run in Workspace unless they are parented to the local player’s character. You will want to use a Script with its RunContext set to Client, if you want to have a script running locally parented to a part.
I also thought maybe the localscript picks up when other players change worlds. Can you send the localscript which plays the music for me to take a look?