So in the game I'm making, you're able to take over control points. Take over all of them and a value for your team called "Moral" is increased by 10, and the other team's value is decreased by 5. The problem is I only want to play a song if the value changes by a positive value, but I only know how to play the song if it changes in general. Here's my script below:
wait(1.2) while true do wait(.1) local Moral = game.Teams.Prussians.Moral.Value local Moral2 = game.Teams.French.Moral.Value script.DieWachtAmRhein:Play() wait(102) script.FrenchAnthem:Play() wait(146.5) script.PreussensGloria:Play() wait(168.5) function ChangedGerman() if Moral == Moral + 10 then -- my attempt to only play a new song if --it changes by a positive value. script.DieWachtAmRhein:Stop() script.FrenchAnthem:Stop() script.PreussensGloria:Stop() game.Workspace.GlobalSoundPlayer.Argonnerwaldlied:Play() game.Teams.Prussians.Moral.Changed:Connect(ChangedGerman) end end end
if Moral >10 then -- Whatever end
That's what I'd think it'd be
As ABK2017 suggested, you need to create an old value and compare the value with the old one.
--Put these outside the while loop local OldMoral = game.Teams.Prussians.Moral.Value local OldMoral2 = game.Teams.French.Moral.Value while true do local Moral = game.Teams.Prussians.Moral.Value local Moral2 = game.Teams.French.Moral.Value --stuff if Moral == OldMoral + 10 then OldMoral = Moral --Do other stuff end end