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?
01 | local part = script.Parent |
02 |
03 | local 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(Vector 3. new(- 28.645 , 7.881 , - 32.997 )) |
10 | humanoid.Health = 0 |
11 | wait( 1 ) |
12 | game.Workspace.LAZER:MoveTo(Vector 3. new(- 159.244 , - 5 , - 30.002 )) |
13 | game.Workspace.imaf.Playing = false |
14 | game.Workspace.imaf.TimePosition = 0 |
15 | end |
16 | end |
17 |
18 | part.Touched:Connect(onPartTouched) |
Btw, the sound is in Workspace, so that might be the problem, dont know where to put it.
Fire a RemoteEvent to a localscript and play the sound from that.
IF YOU MADE A REMOTE EVENT CALLED "FireLaserSound" IN REPLICATEDSTORAGE
1 | local PlayerService = game:GetService( "PlayerService" ) |
2 |
3 | local player = PlayerService:GetPlayerFromCharacter(humanoid.Parent) |
4 |
5 | game.ReplicatedStorage.FireLaserSound:FireClient(player) |
Localscript in StarterPlayerScripts:
1 | game.ReplicatedStorage.FireLaserSound.OnClientEvent:Connect( function () |
2 | -- play the sound here |
3 | end ) |
Make a RemoteEvent in replicated storage When player touch:
1 | local 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 |
7 | end |
Make a LocalScript in StarterGui
1 | game.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 |
3 | end ) |