Sounds not playing locally when teleporting

Hello,

So I have this teleportation thing in my game to where when you step on Pad1 (for example) you get teleported to Pad2. The thing is that I’m trying to make a sound from Workspace play locally whenever you teleport but atm it’s playing for everyone. I’ve looked up threads on how to make sounds play locally but they weren’t very helpful for my situation as I got 2 different scripts going on for this. Here’s how they’re set up:

The TP script in Workspace:

The code:

local Pad2 = game.Workspace.Pad2

script.Parent.Touched:Connect(function(touchPart)
	if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then
		local Character = touchPart.Parent
		local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)
		Character:SetPrimaryPartCFrame(teleportLocation)
		game.Workspace.loading:Play()

		local teleportingValue = Character.currentlyTeleporting
		teleportingValue.Value = true
		wait(3)
		teleportingValue.Value = false
	end
end)

and the supposed LocalScript to play sounds locally:

image

The code:

local Pad1 = workspace.Pad1
local jumpscare = game.Workspace.jumpscare
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local DB = false

Pad1.Touched:Connect(function(Hit)
	if not DB and Character == Hit.Parent then 
		DB = true
		jumpscare:Play()
		DB = false
	end
end)

Clip of everything in action:

I got my alt to join the game with me to test if it really played locally now but for some reason, it still plays for everyone. I know that there’s a way to properly set this up and get it to work but since I’m not very experienced in scripting, I’m struggling a bit to figure this issue out. I’d appreciate anyone who could be kind enough to explain me through this annoying issue!

Instead of using alts, you can use the local server feature inside the Test tab. Also I’m unable to locate the issue but switching to Remotes may fix it(and also make you get rid of debounces and such):

--rest of your code goes here
local player = game.Players:GetPlayerFromCharacter(touchPart.Parent)
Character:SetPrimaryPartCFrame(teleportLocation)
--Jumpscare is a RemoteEvent inside ReplicatedStorage
ReplicatedStorage.Jumpscare:FireClient(player)
game.Workspace.loading:Play()

and in your client script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Remote = ReplicatedStorage:WaitForChild("Jumpscare")

local jumpscare = workspace.jumpscare

Remote.OnClientEvent:Connect(function()
	jumpscare:Play()
end)

Basically remotes can be used to communicate between the server and client.

2 Likes

Wait, so this is what I should be putting in the normal script from Workspace? Or like am I supposed to try and fit this in the code I previously had for it or what exactly? I already made the “Jumpscare” RemoteEvent and put the code you provided for the LocalScript but am still a bit confused on how to do with the teleportation script as you put “rest of your code goes here” and am questioning like if I fit it in somehow or switch some things up or… Since as you know, the goal is that whenever you touch Pad1, you get teleported to Pad2 with the sound effect that plays locally. Pardon if my explanation is a bit confusing haha.