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

How would I insert sound into the playergui after the localplayer dies?

Asked by 6 years ago

How would i insert a sound into the playergui after the localplayer dies?

im trying to make a sprint script that when u sprint it makes sounds and stuff and when u join in the game it inserts them in with the script i made but i dont have a script to insert the sounds back in when they die, so when they die the sounds wont work because they wont be in the player gui. so would it be possible to keep them in there even after they die or just re insert them after a player dies?

2 answers

Log in to vote
1
Answered by
Newrown 307 Moderation Voter
6 years ago

To solve this problem, we can use the PlayerAdded event and the CharacterAdded event of the player.

The code under the CharacterAdded event runs everytime a player respawns.

So it would look something like this:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character) -- sets up the function for every player that enters
        local sound = Instance.new("Sound") -- create sound object
        local soundId = 3434 -- change this to the soundId you want to play
        sound.Parent = player.PlayerGui -- parent it to the playergui of the player
        sound.SoundId = soundId
    end)
end)

Anyways, you get the idea, you can add the rest yourself.

Hope it helped!

Ad
Log in to vote
0
Answered by
arshad145 392 Moderation Voter
6 years ago

I would prefer to use a Humanoid.Died:function()

local nsound = Instance.new("Sound")
nsound.SoundId = "Sound Id you want."
nsound.blahblah -- Sound properties Amplify or whatever you want.
nsound.Parent = game.ReplicatedStorage -- or Parent wherever you want to keep it.

game:GetService('Players').PlayerAdded:connect(function(player)--Fired when Player connects

    player.CharacterAdded:connect(function(character)--Fired when Character is created

        character:WaitForChild("Humanoid").Died:connect(function() -- Fired when Humanoid; player died...
            --Stuff?
            local sound = ReplicatedStorage:findFirstChild("sound"):Clone--Clone the previous sound 
        end)
            sound.Parent = character -- Parent the Clone to new reborn character.
    end)
end)

Still new to RbxLua , so explain if I am not right.

Thank you for reading.

Answer this question