All players can hear the sound. I want to make sure that only the player who stepped on a specific part can hear the sound

All players can hear the sound. I want to make sure that only the player who stepped on a specific part can hear the sound

local part = script.Parent

local debounce = false

local SoundService = game:GetService("SoundService")

local bgm = SoundService.BackgroundMusic

local speed =SoundService.Speed

part.Touched:Connect(function(hit)

if game.Players:GetPlayerFromCharacter(hit.Parent.Parent.Parent:WaitForChild("DriveSeat").Occupant.Parent) ==nil then return end

bgm:Stop()

speed:Play()

end)

Use a remote event that fires from the client, or run the code on the client through a local script.

1 Like

No sound is played when playing in local script

Any errors? sound does play inside of localscripts. Try using prints to see if the code is even running.

Do you put the sound file in the sound service?

You can but if you want it to sound like its coming out of the part instead of straight through the players speakers you can put it in the part.

debounce = false

script.Parent.Touched:connect(function(hit)

if not debounce then

debounce = true

if(hit.Parent:FindFirstChild("Humanoid")~=nil)then

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

local sound = script.Parent.Sound:Clone()

sound.Parent = player.PlayerGui

sound:Play()

wait(60)--change to how long before the sound plays again after retouching it

end

debounce = false

end

end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.