Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the sound only play for Localplayer?

Asked by 3 years ago

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?

01local part = script.Parent
02 
03local function onPartTouched(otherPart)
04    local partParent = otherPart.Parent
05    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
06    if humanoid then
07        game.Workspace.imaf.Playing = true
08        wait(3.3)
09        game.Workspace.LAZER:MoveTo(Vector3.new(-28.645, 7.881, -32.997))
10        humanoid.Health = 0
11        wait(1)
12        game.Workspace.LAZER:MoveTo(Vector3.new(-159.244, -5, -30.002))
13        game.Workspace.imaf.Playing = false
14        game.Workspace.imaf.TimePosition = 0
15    end
16end
17 
18part.Touched:Connect(onPartTouched)

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

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

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

1local PlayerService = game:GetService("PlayerService")
2 
3local player = PlayerService:GetPlayerFromCharacter(humanoid.Parent)
4 
5game.ReplicatedStorage.FireLaserSound:FireClient(player)

Localscript in StarterPlayerScripts:

1game.ReplicatedStorage.FireLaserSound.OnClientEvent:Connect(function()
2    -- play the sound here
3end)
0
Also Didn't work, sorry Jakob_Cashy 79 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Make a RemoteEvent in replicated storage When player touch:

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

Make a LocalScript in StarterGui

1game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function() -- Runs when remote fired on client.. i think thats how i explain it?
2    -- Play the sound here and it will only do for localplayer
3end)
0
Didn't work. Jakob_Cashy 79 — 3y

Answer this question