Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make the sound only play for Localplayer?

This script inside a block activates a sound, moves a "lazer" and kills player, but, the sound is playing for everyone in the server, how can I just make the sound play for the LocalPlayer?

local part = script.Parent

local function onPartTouched(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		game.Workspace.imaf.Playing = true
		wait(3.3)
		game.Workspace.LAZER:MoveTo(Vector3.new(-28.645, 7.881, -32.997))
		humanoid.Health = 0
		wait(1)
		game.Workspace.LAZER:MoveTo(Vector3.new(-159.244, -5, -30.002))
		game.Workspace.imaf.Playing = false
		game.Workspace.imaf.TimePosition = 0
	end
end

part.Touched:Connect(onPartTouched)

Btw, the sound is in Workspace, so that might be the problem, dont know where to put it.

2 answers

Fire a RemoteEvent to a localscript and play the sound from that.

IF YOU MADE A REMOTE EVENT CALLED "FireLaserSound" IN REPLICATEDSTORAGE

local PlayerService = game:GetService("PlayerService")

local player = PlayerService:GetPlayerFromCharacter(humanoid.Parent)

game.ReplicatedStorage.FireLaserSound:FireClient(player)

Localscript in StarterPlayerScripts:

game.ReplicatedStorage.FireLaserSound.OnClientEvent:Connect(function()
	-- play the sound here
end)

1 comment

0

Also Didn't work, sorry

Make a RemoteEvent in replicated storage When player touch:


local function onPartTouched(otherPart)
   	local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local player  = game.Players:GetPlayerFromCharactcer(humanoid.Parent)
		game.ReplicatedStorage.RemoteEvent:FireClient(player) -- Fire on client
	end
end

Make a LocalScript in StarterGui

game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function() -- Runs when remote fired on client.. i think thats how i explain it?
	-- Play the sound here and it will only do for localplayer
end)

1 comment

0

Didn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.