How would I make it so this plays only for the player who touched the part

Hello! So am making a localscript where if the player touched a part/hitbox it would play a sound. But if one plays it then it plays for everyone? how would I fix that

localscript:

local Arcade = game.Workspace.Arcade
local ArcadeHitBox = Arcade.Hitbox
local Arcade2 = game.Workspace.Arcade2
local ArcadeHitBox2 = Arcade2.Hitbox
local Freddy = game.Workspace.Freddy
local FreddyHitBox = Freddy.Hitbox

local Debounce = false
local Debounce2 = false

ArcadeHitBox.Touched:Connect(function(player)
	if Debounce == false then
		Debounce = true
		Arcade.Arcade.Screen.Color = Color3.new(1, 1, 1)
		local Sound = math.random(1,3)
		if Sound == 1 then
			player.PlayerGui.GlitchEffect.Glitch:Play()
		elseif Sound == 2 then
			player.PlayerGui.GlitchEffect.Glitch2:Play()
		elseif Sound == 3 then
			player.PlayerGui.GlitchEffect.Glitch3:Play()
		end
		wait(3)
		script.Parent.Glitch:Stop()
		script.Parent.Glitch2:Stop()
		script.Parent.Glitch3:Stop()
		Arcade.Arcade.Screen.Color = Color3.new(0, 0, 0)
		Debounce = false
		ArcadeHitBox.Parent = script
		wait(30)
		script.Hitbox.Parent = Arcade
	end
end)

ArcadeHitBox2.Touched:Connect(function(player)
	if Debounce == false then
		Debounce = true
		Arcade2.Arcade.Screen.Color = Color3.new(1, 1, 1)
		local Sound = math.random(1,3)
		if Sound == 1 then
			player.PlayerGui.GlitchEffect.Glitch:Play()
		elseif Sound == 2 then
			player.PlayerGui.GlitchEffect.Glitch2:Play()
		elseif Sound == 3 then
			player.PlayerGui.GlitchEffect.Glitch3:Play()
		end
		wait(3)
		script.Parent.Glitch:Stop()
		script.Parent.Glitch2:Stop()
		script.Parent.Glitch3:Stop()
		Arcade2.Arcade.Screen.Color = Color3.new(0, 0, 0)
		Debounce = false
		ArcadeHitBox2.Parent = script
		wait(30)
		script.Hitbox.Parent = Arcade2
	end
end)

FreddyHitBox.Touched:Connect(function(player)
	if Debounce == false then
		Debounce = true
		local Sound = math.random(1,3)
		if Sound == 1 then
			player.PlayerGui.GlitchEffect.Glitch:Play()
		elseif Sound == 2 then
			player.PlayerGui.GlitchEffect.Glitch2:Play()
		elseif Sound == 3 then
			player.PlayerGui.GlitchEffect.Glitch3:Play()
		end
		wait(3)
		script.Parent.Glitch:Stop()
		script.Parent.Glitch2:Stop()
		script.Parent.Glitch3:Stop()
		Debounce = false
		FreddyHitBox.Parent = script
		wait(30)
		script.Hitbox.Parent = Freddy
	end
end)

Anything in a localscript will only be changed to the client. The only exception is if it’s a replicated event / function / object.

This includes animations, modules, remote event / functions and much more. Sounds however isn’t one of these.

Therefore, it should be playing locally within a localscript.

Have you tested it and is there any other script that handles the sounds?

Your code runs whenever the HitBoxes are touched, regardless of if they have been touched by the client or another client. Check that the part which Touched the hitbox is a descendant of the local player’s character.

e.g

local LocalPlayer = game:GetService("Players").LocalPlayer

FreddyHitBox.Touched:Connect(function(Hit)
	if LocalPlayer.Character and Hit:IsDescendantOf(LocalPlayer.Character) then
		--Play sound
	end
end)

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