[REPOST] :GetMarkerReachedSignal running multiple times in one use

I am trying to make when ever the anim event is reached, the enemy player takes damage.
However, the :GetMarkerReachedSignal() runs like 7x the amount it needs to. (one)
Even though I have a return at the end, which should stop this from happening.
I have tried a bunch of things and am tired of doing so.

Heres my code:

playerPlay:GetMarkerReachedSignal("Hit"):Connect(function() --playerPlay is my anim
					if vicHum.Health > script.damage.Value then --vicHum is the enemys Humanoid
						vicHum:TakeDamage(script.damage.Value)
						else
						vicHum.Health = 1
					end
				return-- this is the return im talking about, which obviously isnt doing its job
				end)

If anyone could help, it would be greatly appreciated!
Thanks!

1 Like

It should fire just one time once the event has been reached. Maybe you have multiple events in your animation? Also it’d be better if you’ve shown full code

It might also happen when animation plays multiple times

What do you mean return isn’t doing its job? If you’re talking about that you want Hit marker signal to only work once, you can just use :Once instead of :Connect.

The return inside the function only returns, but the RBXScriptSignal remains. Alternatively, you put the event under a variable and disconnect it after use, but in this case you seem to just be able and use :Once

This is my entire script… and yes, i have 2 anim events labeled hit in the event. Should they all be labeled differently?

script.Fire.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local plrHum = char:FindFirstChild("Humanoid")
	local rp1 = char.HumanoidRootPart
	local grab,victim,player = script.Grab,script.Victim,script.Player
	local hb = require(game.ReplicatedStorage.HitboxStuff.hitboxModule)
	local kb = require(game.ReplicatedStorage.KnockbackModule)
	local d = game:GetService("Debris")
	local rocks = require(game.ReplicatedStorage.Rock)
	local grabPlay = plrHum:LoadAnimation(grab)
	grabPlay:Play()
	
	grabPlay:GetMarkerReachedSignal("Hit"):Connect(function()
		local x
		
		hb.Create(plr, char)
		
		x = workspace:WaitForChild("Hitbox "..plr.Name)
		
		d:AddItem(x, 0.5)
		
		for i,v in pairs(workspace:GetPartsInPart(x)) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= char and not v.Parent:FindFirstChild("iframes").Value then
				local vicHum = v.Parent:FindFirstChild("Humanoid")
				local rp2 = v.Parent.HumanoidRootPart
				local playerPlay = plrHum:LoadAnimation(player)
				playerPlay:Play()
				local victimPlay = vicHum:LoadAnimation(victim)
				victimPlay:Play()
				
				rp2.CFrame = rp1.CFrame * CFrame.new(0,0,0)
				rp1.CFrame = rp2.CFrame * CFrame.new(0,0,0)
				plrHum.AutoRotate = false
				vicHum.AutoRotate = false
				rp1.Anchored = true
				rp2.Anchored = true
				
				playerPlay:GetMarkerReachedSignal("Hit"):Connect(function()
					if vicHum.Health > script.damage.Value then
						vicHum:TakeDamage(script.damage.Value)
						print("dmg")
					else
						vicHum.Health = 1
					end
					


					
					local sound = Instance.new("Sound")
					sound.Parent = plr.Character.PrimaryPart
					sound.SoundId = "rbxassetid://6706979361"
					sound:Play()

					d:AddItem(sound, sound.TimeLength)
					return
				end)
						
				
				
				playerPlay:GetMarkerReachedSignal("FinalHit"):Connect(function()
					if vicHum.Health > script.finalDamage.Value then
						vicHum:TakeDamage(script.finalDamage.Value)
					else
						vicHum:TakeDamage(1 * 1000)
					end
					v.Parent.RagdollTrigger.Value = true
					local sound = Instance.new("Sound")
					sound.Parent = plr.Character.PrimaryPart
					sound.SoundId = "rbxassetid://6750490488"
					sound:Play()

					d:AddItem(sound, sound.TimeLength)
					
					plrHum.AutoRotate = true
					vicHum.AutoRotate = true
					rp1.Anchored = false
					rp2.Anchored = false
					
					kb.KB1(plr, 80000, 30, rp2, .3)
					script.UnStun.Enabled = true
					wait(.5)
					script.UnStun.Enabled = false
					wait(2.5)
					v.Parent.RagdollTrigger.Value = false
					return
				end)
				    
					
				
			end
		end
	end)
end)```
1 Like

You’re using for i,v in pairs() and in which you put the :GetMarkerReachedSignal event, so for each instance found in for loop it will create separate :GetMarkerReachedSignal function, that’s why it activates multiple times

Oh… Haha!! Thats very obvious! I dont know how i didnt notice that! So would i just use the for i loop to set a variable (that would be the enemy) then just put all the old code that was in the for i loop outside of it and use that new variable to reference the enemy?

Nah, actually if you’re just trying to find one instance you can create a variable outside with which you would check if that instance was already found.

Example:

local Found = false
for i, v in pairs(blabla:GetChildren()) do
 if v and Found == false then
   Found = true
 end
end

Or instead you can create a table in which you check if the instance was found and put that instance into a table and then check if that instance is already in table or not

Sorry for all the questions, but with this code, where would it go in my script? (im kinda bad at this)

Outside of for i’v loop or outside your grabPlay GetMarkerReachedSignal event

So then how would I use this to get the enemy? (like i said, im bad)

If you want to set a VARIABLE you put it outside the function and then use that variable inside the function

And please explain better what are you exactly trying to do

1 Like

Yeah i still dont get this, what im doing is this:

Its an attack move for a fighting game im making. Im using anim events to check for when the damage is to be dealt. Except when i do that, (i have a print statement for debugging) and it prints way more than it should. Im really bad at explaining so sorry about that.
I understand what the issue is, i just don’t know how to fix it.

Wrote this on phone

local CheckTable = {}
for i,v in pairs(workspace:GetPartsInPart(x)) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= char and not v.Parent:FindFirstChild("iframes").Value then
if not CheckTable[v.Parent] then
CheckTable[v.Parent] = v.Parent
				local vicHum = v.Parent:FindFirstChild("Humanoid")
				local rp2 = v.Parent.HumanoidRootPart
				local playerPlay = plrHum:LoadAnimation(player)
				playerPlay:Play()
				local victimPlay = vicHum:LoadAnimation(victim)
				victimPlay:Play()
				
				rp2.CFrame = rp1.CFrame * CFrame.new(0,0,0)
				rp1.CFrame = rp2.CFrame * CFrame.new(0,0,0)
				plrHum.AutoRotate = false
				vicHum.AutoRotate = false
				rp1.Anchored = true
				rp2.Anchored = true
				
				playerPlay:GetMarkerReachedSignal("Hit"):Connect(function()
					if vicHum.Health > script.damage.Value then
						vicHum:TakeDamage(script.damage.Value)
						print("dmg")
					else
						vicHum.Health = 1
					end
					


					
					local sound = Instance.new("Sound")
					sound.Parent = plr.Character.PrimaryPart
					sound.SoundId = "rbxassetid://6706979361"
					sound:Play()

					d:AddItem(sound, sound.TimeLength)
end
					return
				end)

Everything breaks when i put that in… hey man, if you really want me to, ill just restart the script?

How does it break exactly? And show me how do you put that in

this is how i put it in (prob wrong):

script.Fire.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local plrHum = char:FindFirstChild("Humanoid")
	local rp1 = char.HumanoidRootPart
	local grab,victim,player = script.Grab,script.Victim,script.Player
	local hb = require(game.ReplicatedStorage.HitboxStuff.hitboxModule)
	local kb = require(game.ReplicatedStorage.KnockbackModule)
	local d = game:GetService("Debris")
	local rocks = require(game.ReplicatedStorage.Rock)
	local grabPlay = plrHum:LoadAnimation(grab)
	grabPlay:Play()
	
	grabPlay:GetMarkerReachedSignal("Hit"):Connect(function()
		local x
		
		hb.Create(plr, char)
		
		x = workspace:WaitForChild("Hitbox "..plr.Name)
		
		d:AddItem(x, 0.5)
		
		local CheckTable = {}
		for i,v in pairs(workspace:GetPartsInPart(x)) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent ~= char and not v.Parent:FindFirstChild("iframes").Value then
				if not CheckTable[v.Parent] then
					CheckTable[v.Parent] = v.Parent
					local vicHum = v.Parent:FindFirstChild("Humanoid")
					local rp2 = v.Parent.HumanoidRootPart
					local playerPlay = plrHum:LoadAnimation(player)
					playerPlay:Play()
					local victimPlay = vicHum:LoadAnimation(victim)
					victimPlay:Play()

					rp2.CFrame = rp1.CFrame * CFrame.new(0,0,0)
					rp1.CFrame = rp2.CFrame * CFrame.new(0,0,0)
					plrHum.AutoRotate = false
					vicHum.AutoRotate = false
					rp1.Anchored = true
					rp2.Anchored = true

					playerPlay:GetMarkerReachedSignal("Hit"):Connect(function()
						if vicHum.Health > script.damage.Value then
							vicHum:TakeDamage(script.damage.Value)
							print("dmg")
						else
							vicHum.Health = 1
						end




						local sound = Instance.new("Sound")
						sound.Parent = plr.Character.PrimaryPart
						sound.SoundId = "rbxassetid://6706979361"
						sound:Play()

						d:AddItem(sound, sound.TimeLength)
					end)
					
					playerPlay:GetMarkerReachedSignal("FinalHit"):Connect(function()
						if vicHum.Health > script.finalDamage.Value then
							vicHum:TakeDamage(script.finalDamage.Value)
						else
							vicHum:TakeDamage(1 * 1000)
						end
						v.Parent.RagdollTrigger.Value = true
						local sound = Instance.new("Sound")
						sound.Parent = plr.Character.PrimaryPart
						sound.SoundId = "rbxassetid://6750490488"
						sound:Play()

						d:AddItem(sound, sound.TimeLength)

						plrHum.AutoRotate = true
						vicHum.AutoRotate = true
						rp1.Anchored = false
						rp2.Anchored = false

						kb.KB1(plr, 80000, 30, rp2, .3)
						script.UnStun.Enabled = true
						wait(.5)
						script.UnStun.Enabled = false
						wait(2.5)
						v.Parent.RagdollTrigger.Value = false
						return
					end)
					
				end
						
				
				
				
				    
					
				
			end
		end
	end)
end)

i have absolutely ZERO errors, but when the remote event fires, literally nothing happens…

Try printing after CheckTable[v.Parent] = v.Parent

And yeah i totally recommend you to rescript it

Nope, nothing happens.
And i guess i will rescript it, but the thing is, i dont know how i would rescript it

You should get into programming logic more.

Maybe someone else would find the reason, but i’m busy rn to analyse whole script

Welp i fixed it- you fixed it, its a little hard to explain how i fixed it since you cant see my explorer, but it worked! Sorry for the troubles man, wish you luck on all of your projects!

1 Like