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

Game plays music if player is greater than stage one?

I'm trying to make it so if the leaderstats of the character is greater than 1 then a welcome back audio plays. The location of everything in the script is correct. I do not know why it will not play.

function onPlayerEntered(player)
	if player.leaderstats.Stage.Value < 1
then game.Workspace.Sounds.Welcomeback:play()
	wait(8)
	game.Workspace.Sounds.Welcomeback.Volume = .4
	wait(.5)
	game.Workspace.Sounds.Welcomeback.Volume = .3
	wait(.5)
	game.Workspace.Sounds.Welcomeback.Volume = .2
	wait(.5)
	game.Workspace.Sounds.Welcomeback.Volume = .1
	wait(.5)
	game.Workspace.Sounds.Welcomeback:pause()


	
	end
	


game.Players.PlayerAdded:connect(onPlayerEntered)

Thank you for the help.

2 comments

0

Is the stage value Loaded before you try to play it? Try adding a player:WaitForDataReady() then try it.

0

In line 2 why are searching to see if a leaderstat's stage is less than 1 when you mentioned you are searching the leaderstat's stage to see if its greater than 1?!?

1 answer

You forgot a end, and you were checking if the value was less then 1 which would be 0, or -1, -2 etc.

function onPlayerEntered(player)
	if player.leaderstats.Stage.Value > 1 then -- Replaced < with >, it'll check if the value is greater
		game.Workspace.Sounds.Welcomeback:Play()
	    wait(8)
	    game.Workspace.Sounds.Welcomeback.Volume = .4
	    wait(.5)
	    game.Workspace.Sounds.Welcomeback.Volume = .3
	    wait(.5)
	    game.Workspace.Sounds.Welcomeback.Volume = .2
	    wait(.5)
	    game.Workspace.Sounds.Welcomeback.Volume = .1
	    wait(.5)
	    game.Workspace.Sounds.Welcomeback:Pause() -- Or stop
	end
end
game.Players.PlayerAdded:connect(onPlayerEntered)

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