I've couldn't figure this out. Can please somebody help me?
How do I make it so that when a player touches a Part that music/sound plays only for him?
1 answer
First things first you grab my model i did a while back and still use today from here : https://www.roblox.com/library/2580560341/SoundKit
and put the Sounds and MusicControl in StarterGui put PlayMusic in ReplicatedStorage and put the part wherever you want in workspace
so when you touch the part this script runs:
local sound = "rbxassetid://1898736620" -- grabs the music id
script.Parent.Touched:connect(function(hit)
if game.Players:findFirstChild(hit.Parent.Name) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.PlayMusic:FireClient(player,sound) -- sends the music id over to the player you want it to play from
end
end)
so that script fires the id to the player who then picks it up with a a script inside of the Sound that i told you to put in StarterGui here:
game.ReplicatedStorage.PlayMusic.OnClientEvent:Connect(function(sound)
if script.Parent.SoundId ~= sound then
script.Parent:Stop()
script.Parent.SoundId = sound
script.Parent:Play()
end
end)
that script grabs the id and sets the Sound's id as that id and plays it but since it is StarterGui it will only play for that specific player that touched the part
now the MusicControl is just optional if you want a mute button but heres the script in it:
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
if script.Parent.Mode.Value == false then
script.Parent.Image = "rbxassetid://333998033"
script.Parent.Mode.Value = true
plr.PlayerGui.Sound.Volume = 0
elseif script.Parent.Mode.Value == true then
script.Parent.Image = "rbxassetid://333998016"
script.Parent.Mode.Value = false
plr.PlayerGui.Sound.Volume = 0.3
end
end)
this script just changes the image of the button that you can set to whatever (i prefer you to change it i use it in all my major projects) but you dont have to and then mutes the music or sets it to 0.3 which for me is a good volume but that said my usual volume is played through a Razer Kraken Pro v2 at 56 volume windows 10 so results may vary but there you go my friend you have your whole system set up and ready to go and if your needing a personal radio just say so i have an edited version of this that has a radio and volume control option
2 comments
Thank you very much
not a problem i had to do this same project a long time ago and never figured it out and found a video on youtube that eventually helped me out figured i would save you the struggle
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Local Scripts