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

How Do I Wait for Character to Load?

Asked by 6 years ago

I have been trying to figure out how to create a script for a character to load first before the other scripts take place. I have been trying to figure this out because I need a sound to play in an area when the character has touched the brick that has the sound in it, however, it only plays for two seconds and then stops because the character is not fully loaded in. Anyone know how to make a script to wait for the character to load? Here are my music scripts.

script.Parent.Touched:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)

    if plr then
        script.Parent.MufiaPlaza:Play()
    end
end)

Here is the second script for when the character leaves the "Part."

script.Parent.TouchEnded:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)

    if plr then
        script.Parent.MufiaPlaza:Stop()
    end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

Ok, so I just made a long answer and figured out that its not the fact that the character isn't loaded thats wrong with your script. Your music is trying to play constantly which means it is going to keep restarting because a player will touch the part infinite times in a second. What you need to do is set a variable to true and make sure that it isn't false before you play the music. Now I hope I helped xD

0
Lmao, I read your previous answers. Yeah, and when I take out the "TouchEnded" script, the music plays perfectly fine... I will try the variable thing right now though. TheMagicalWell 2 — 6y
0
If you need a wiki reference, @cmgtotalyawesome was talking about debounce: http://wiki.roblox.com/index.php?title=Debouncel WillieTehWierdo200 966 — 6y
0
Thank you so much! :) I never used the debounce code before, so I guess it is time to learn some more ;I TheMagicalWell 2 — 6y
Ad

Answer this question