Need help on my scripters script

So my for the most part newer scripter needs help on coding our Combat Music script. It’s suppose to check for when the player takes damage, play combat music (Would fade in), and after 5.5 seconds, it would end (Fade out).

  1. What do you want to achieve?
    I want to achieve a script that can basically play music when you take damage
  2. What is the issue? Include screenshots / videos if possible!
    Not sure, but the script from what we know of just wont play the music, I’ve changed it to be put inside SoundService, still didn’t work, put in Workspace, still didn’t work, and finally what we put it back in ReplicatedStorage, STILL didn’t work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Haven’t checked the Dev Hub but we’ve tried placing it in different areas of the engine (replicatedstorage, soundservice, workspace, in and out of a folder also)
    Script and wheres its located here -

    137ac4e3bd68aa51ab5f36e1c96ba3bc

Other than that uh yeah, we just need some help on it! :smiley:

Oh boy.

  1. You can just get the elapsed time since the Event happened using tick() or time().

  2. you should be using TweenService or a loop, instead of waiting every .1 seconds for it to change.

Because LocalScripts cannot run in those environments, if you didnt read where they could run.

1 Like

The problem is that, since you’re using the same health variable, your health is not going to be less than your health, and they will always be the same value.

local damagemusic = game.ReplicatedStorage.Sounds["Combat Music"]

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local combatvalue = Instance.new("BoolValue",char)
		local oldhealth = char.Humanoid.Health -- Health before HealthChanged runs
		
		char.Humanoid.HealthChanged:Connect(function(health)
			if health < oldhealth then -- Checks if new health is lower
				-- Put code here
			end
			oldhealth = health -- New value for health to check if it is greater or lower
		end)
	end)
end)

Also I’d suggest instead of using many wait()s, you can use a Tween or for i = 1,10 loop.

1 Like

Sorry for a late reply, I notified my scripter and yeah he thanks you, I can read code and I asked him about it, and he said it should work, but yeah after reading this it fixed the problem. Thanks :smiley:

And thank you for that, also told him about that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.