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!
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
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
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.
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)
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!