I wanted to Play a sound/song on a Part, But Nothing happened, There wasn't anything in output either! Here is my code:
s=Instance.new("Sound") player=game.Players.LocalPlayer health=player.Character.Humanoid while true do if health.Health==100 then s:Play() s.Parent=script.Parent--The Parent is a part. s.SoundId="rbxassetid://144260719"--asset s.Volume=1 s.Looped=true elseif health.Health==0 then--To Stop the glitching. s:stop()--stops when Player is dead. end end--end
Please Respect that I am a Scripter in need for knowledge
You didn't put a wait() in the loop, you set the SoundId after you called Play() on the Sound object, and you don't need a loop if the Sound is looped. Here, I decided to rewrite your code for you, and explain what I wrote.
local player = game.Players.LocalPlayer local sound = Instance.new("Sound", script.Parent) local humanoid = player.Character.Humanoid sound.SoundId = "rbxassetid://144260719" sound.Looped = true sound.Volume = 1 sound:Play() humanoid.Died:connect(function() --instead of having a loop that could lag the game, this just stops the sound when the Humanoid dies sound:Stop() end)
Notice how I set all the properties of the Sound object before I wrote the "actual" code. I always do this so I don't have to suffer with confusion later in the script, since I'm always adding and removing parts of my scripts. If you have any questions, please comment! If this answer helps, please upvote and accept!
Locked by adark and Redbullusa
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?