Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The sound won't play in the player. What is happening?

local sound = {2629666914, 1943645778, 3094708023, 1797517374, 2559967558}


game:GetService("Players").PlayerAdded:Connect(function(plr)
	local soundObject = Instance.new("Sound",plr)
	local stage = plr.leaderstats.Stages.Value
	soundObject.SoundId = "rbxassetid://"..sound[1]	
	repeat soundObject.TimePosition = 0
		soundObject:Play()
		soundObject.Ended: wait()
	until stage >= 9
	soundObject.SoundId = "rbxassetid://"..sound[2]	
	repeat soundObject.TimePosition = 0
		soundObject:Play()
		soundObject.Ended: wait()
	until stage >= 21
	soundObject.SoundId = "rbxassetid://"..sound[3]	
	repeat soundObject.TimePosition = 0
		soundObject:Play()
		soundObject.Ended: wait()
	until stage >= 31
end)

It won't seem to play

2 answers

You have a space between Ended and Wait()


local sound = {2629666914, 1943645778, 3094708023, 1797517374, 2559967558}


game:GetService("Players").PlayerAdded:Connect(function(plr)
    local soundObject = Instance.new("Sound",plr)
    local stage = plr:WaitForChild("leaderstats"):WaitForChild("Stages").Value
    soundObject.SoundId = "rbxassetid://"..sound[1] 
    repeat
        soundObject:Play()
        soundObject.Ended:Wait()
 until stage >= 9
    soundObject.SoundId = "rbxassetid://"..sound[2] 
    repeat
        soundObject:Play()
        soundObject.Ended:Wait()
    until stage >= 21
    soundObject.SoundId = "rbxassetid://"..sound[3] 
    repeat
        soundObject:Play()
        soundObject.Ended:Wait()
until stage >= 31
end)

5 comments

0

It doesn't make a difference....

0

I just edited it, can you try it again?

0

The SoundId doesnt seem to change

0

Did you change your stage?

0

Yes

Some stuff here may not answer your question, but it is here to help you out even more.

First of all, the reason may be that you are trying to play it inside of the player itself. The player object has no real world space meaning the sound could be no where near the character.

Second of all you used this to loop a sound

repeat
        soundObject:Play()
        soundObject.Ended:Wait()
until stage >= 9

Although you should do something more like this:

soundObject.looped = true

and also taking the value before the loop will cause it to stay the same. Thus making the loop never stop.

To get the stage use something more like

local stageObject = plr:WaitForChild("leaderstats"):WaitForChild("Stages")

and when you need the value just do stageObject.Value

This can also help out if you just set the sound object to looped. You can use:

stageObject:GetPropertySignalChanged("Value"):Connect(function()
	if stageObject.Value == 9 then
		soundObject:Stop()
	end
end)

the function GetPropertySignalChanged() takes one parameter, the property. It essentially checks to see if the property has changed. Useful for things like this.

I do hope this helps! Comment on this if their is anything else needed.

7 comments

0

The thing is when datastore loads, it won't stop everytime.

0

well try putting the sound somewhere else instead of the player, like workspace. Set the maxDistance to inf and it may be heard.

0

well try putting the sound somewhere else instead of the player, like workspace. Set the maxDistance to inf and it may be heard.

0

I'm trying to make the sound local, so it doesnt change for every body

0

do it in a local script.

0

local scripts dont work in workspace

0

Sorry for late response, put the local script somewhere where it will work, like starter player scripts.

This discussion is preserved as it was. New answers, comments, and votes are closed.