Learning as i go from my mistakes, go easy on me.
This worked in another project so i copied it to a new one, now i cannot hear the sound outside of studio(Server).
Game is Non-FE and i cannot find the difference/Error between my two projects.
01 | db = false |
02 | script.Parent.Touched:connect( function (hit) |
03 | if hit.Parent:FindFirstChild( 'Humanoid' ) then |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if db = = false then |
06 | db = true |
07 | script.Parent.Transparency = 1 |
08 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 |
09 | player.Backpack:WaitForChild( 'Kaching' ) |
10 | player.Backpack.Kaching:Play() |
11 | wait(math.random( 30 , 60 )) |
12 | script.Parent.Transparency = 0 |
13 | db = false |
14 | else |
15 | end |
16 | end |
17 | end ) |
Hi Yish,
Backpack
. If you want a Sound to be local, as in heard only by one player, then you need to place it into the CurrentCamera
or the Player
itself. However, keep in mind that the CurrentCamera
is client-side only. So, you must use a LocalScript
to access it. Therefore, you need to fire a RemoteEvent from the Server to set off the LocalScript
. Then, this LocalScript will parent the Sound and play it.01 | local players = game:GetService( "Players" ); |
02 | local player = players.LocalPlayer; |
03 | local rs = game:GetService( "ReplicatedStorage" ); |
04 | local parent_sound_ev = rs:WaitForChild( "Parent Sound" ); |
05 | local cam = workspace.CurrentCamera; |
06 |
07 | function parent_it() |
08 | local sound = script:WaitForChild( "Kaching" ):Clone(); |
09 | local prev_sound = cam:FindFirstChildOfClass( "Sound" ); |
10 |
11 | if prev_sound then |
12 | prev_sound:Destroy(); |
13 | end |
14 |
15 | sound.Parent = cam; |
16 | sound:Play(); |
17 | end |
18 |
19 | parent_sound_ev.OnClientEvent:Connect(parent_it); |
01 | db = false |
02 | local rs = game:GetService( "ReplicatedStorage" ); |
03 | local play_sound = rs:WaitForChild( "Parent Sound" ) |
04 |
05 | script.Parent.Touched:connect( function (hit) |
06 | if hit.Parent:FindFirstChild( 'Humanoid' ) then |
07 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | if db = = false then |
09 | db = true |
10 | script.Parent.Transparency = 1 |
11 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 |
12 | play_sound:FireClient(player); |
13 |
14 | wait(math.random()) |
15 | script.Parent.Transparency = 0 |
16 | db = false |
17 | else |
18 | end |
19 | end |
20 | end ) |
Thanks,
Best regards,
~~ KingLoneCat