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

Making a sound in a model play locally?

Asked by 7 years ago

I would like OpenSound1 to play locally (currently it is playing globally all over the map). I have been trying to figure this out myself but I just keep breaking it :( Line 37 is when the sound plays. I appreciate the help so much! Thank you in advance!

print("Advanced SpecialDoor Script loaded")



permission = { "Fire Dorm" }
Door = script.Parent.Parent.PersonDoor
DoorMesh = script.Parent.Parent.PersonDoor.Mesh
Sensor = script.Parent

function checkOkToLetIn(name)
    for i = 1,#permission do

        if (string.upper(name) == string.upper(permission[i])) then return true end
    end
    return false
end

function onTouched(hit)
        print("Sensor Hit")
        local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil ) then
            -- 
            print("Human touched door")

            if (checkOkToLetIn(human.Parent.Name)) then
                print("Human passed test")
                Wait(0.001)
                                script.Parent.Parent.Dot1.Transparency = 0
                                wait(0.4)
                                script.Parent.Parent.Dot2.Transparency = 0
                wait(0.4) 
                                script.Parent.Parent.Dot3.Transparency = 0
                wait(0.4) 
                                script.Parent.Parent.Open.Transparency = 0
                                script.Parent.Parent.Close.Transparency = 1
                                wait(0.2)
                                script.Parent.Parent.OpenSound1:Play()
                                wait(0.1)
                                script.Parent.Parent.OpenSound2:Play()
                                script.Parent.Parent.HandlePart3.Transparency = 0
                                script.Parent.Parent.HandlePart4.Transparency = 0
                                script.Parent.Parent.HandlePart.Transparency = 1
                                script.Parent.Parent.HandlePart2.Transparency = 1
                                script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.9, 0.5, 1.01)
                                Door.Transparency = 0
                                wait(0.02)
                Door.CanCollide = false
                                script.Parent.Parent.Dot1.Transparency = 1
                                script.Parent.Parent.Dot2.Transparency = 1
                                script.Parent.Parent.Dot3.Transparency = 1
                wait(3) 

                                script.Parent.Parent.Open.Transparency = 1
                                script.Parent.Parent.Close.Transparency = 0
                                script.Parent.Parent.HandlePart3.Transparency = 1
                                script.Parent.Parent.HandlePart4.Transparency = 1
                                script.Parent.Parent.HandlePart.Transparency = 0
                                script.Parent.Parent.HandlePart2.Transparency = 0
                                script.Parent.Parent.OpenSound2:Play()
                                wait(0.1)
                                script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.01, 0.01, 0.01)
                Door.CanCollide = true
                Door.Transparency = 0 
            end
        end

end

connection = Sensor.Touched:connect(onTouched) 

0
Place the sound inside the player. For instance the PlayerGui. Everything inside the player is local. nanaluk01 247 — 7y
0
I think he meant, for example, you here the sound if you are this close. As you get farther away, it grows quieter. You know, like real life Gey4Jesus69 2705 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

There is actually a really simple fix to your problem.

To play a sound locally, you need to have the sound somewhere in the Player (I will be using your script a bit in this.)




print("Advanced SpecialDoor Script loaded") permission = { "Fire Dorm" } Door = script.Parent.Parent.PersonDoor DoorMesh = script.Parent.Parent.PersonDoor.Mesh Sensor = script.Parent function checkOkToLetIn(name) for i = 1,#permission do if (string.upper(name) == string.upper(permission[i])) then return true end end return false end function onTouched(hit) print("Sensor Hit") local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil ) then -- print("Human touched door") plr=game.Players:GetPlayerFromCharacter(hit.Parent) if (checkOkToLetIn(human.Parent.Name)) then print("Human passed test") Wait(0.001) script.Parent.Parent.Dot1.Transparency = 0 wait(0.4) script.Parent.Parent.Dot2.Transparency = 0 wait(0.4) script.Parent.Parent.Dot3.Transparency = 0 wait(0.4) script.Parent.Parent.Open.Transparency = 0 script.Parent.Parent.Close.Transparency = 1 wait(0.2) plr.PlayerGui.OpenSound1:Play() wait(0.1) plr.PlayerGui.OpenSound2:Play() script.Parent.Parent.HandlePart3.Transparency = 0 script.Parent.Parent.HandlePart4.Transparency = 0 script.Parent.Parent.HandlePart.Transparency = 1 script.Parent.Parent.HandlePart2.Transparency = 1 script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.9, 0.5, 1.01) Door.Transparency = 0 wait(0.02) Door.CanCollide = false script.Parent.Parent.Dot1.Transparency = 1 script.Parent.Parent.Dot2.Transparency = 1 script.Parent.Parent.Dot3.Transparency = 1 wait(3) script.Parent.Parent.Open.Transparency = 1 script.Parent.Parent.Close.Transparency = 0 script.Parent.Parent.HandlePart3.Transparency = 1 script.Parent.Parent.HandlePart4.Transparency = 1 script.Parent.Parent.HandlePart.Transparency = 0 script.Parent.Parent.HandlePart2.Transparency = 0 plr.PlayerGui.OpenSound2:Play() wait(0.1) script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.01, 0.01, 0.01) Door.CanCollide = true Door.Transparency = 0 end end end connection = Sensor.Touched:connect(onTouched)
0
Thank you for your response! I believe I am missing something very crucial here that may just change my life.. I am only able to access PlayerGui when I am in test mode (and it does not save changes when I perform actions in this mode). What is the actual way to access this? Thank you so much for your help! callmehbob 54 — 7y
0
What do you mean you cannot access it? Have you tried cloning the sound and placing it directly into the player's playergui? Tempestatem 884 — 7y
0
Well, I am trying to access it by going through Players > Player1 > PlayerGui is this the right path? This only shows up when I am in "test" mode of studio. When I am in edit mode, I can see the "Players" folder, but does not have a drop down list for players because there are not players in editing mode.. I have tried going into "test" mode pasting it into the PlayerGui, but things you do in edit callmehbob 54 — 7y
0
but things you do in edit mode do not save. I am guessing there may be a 3rd way of editing it, with your player in the game and it actually save changes? Because that is the only way I can access this folder, but it does not save in test mode... callmehbob 54 — 7y
View all comments (4 more)
0
I think I may have managed to make it stick, no idea how, but what would I change Player1 to to make it play for everyone (not just Player1)? Example: I have game.Players.Player1.PlayerGui.OpenSound1:Play() , thanks again for your help! callmehbob 54 — 7y
0
Sorry for the late response, i'll add an example in my answer.. Tempestatem 884 — 7y
0
I really appreciate you trying to help, I had tried the script and messed with it a bit but unfortunately no luck. Thank you so much again for trying to help me. I will give you the accepted answer. callmehbob 54 — 7y
0
Hey i'm glad to help. Once you learn how to do the small stuff, you can start learning the bigger stuff, which is where i'm at. Tempestatem 884 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

To make a sound play locally, you put the sound inside a player. For this, we can use PlayerGui. To access PlayerGui, we do this:

game.Players.PlayerAdded:connect(function(p)
    local sound = game.Soundscape.Sound
    local clone = sound:Clone()
    clone.Parent = p.PlayerGui
    clone.Playing = true
end)

Answer this question