Hello folks of the devforum. Today I seek answers to a question I have been asking myself and searching for. I want to make a part that once touched will trigger a local script that will play a sound. The reason I wish to do this is for a mystery quest game where the player enters the map and hears a background song but only the local player hears it so that way when they progress in the game, there wont be the future sound playing for people who just began. Does anyone have a solution?
You can add the sound inside StarterPlayerScripts and set Playing to true, and that should play whenever a player joins
Or
Listen for the touched event locally
Client:
local Plr = game:GetService("Players").LocalPlayer;
local Db = false;
local TouchConnect;
local function onTouch(Hit)
if (hit.Parent:FindFirstChild("Humanoid")) and (game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) == Plr )then
if not Db then
Db = true;
Audio:Play()--<Start playing audio
TouchConnect:Disconnect()--<Disconnect if you're not going to use again
end;
end;
end;
TouchConnect = Item.Touched:Connect(onTouch);