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

How do I make it so it detects when players are touched during a animation?

I have a script where the arm gets launched at a player using a animation. The problem is the touched events don't work unless the players turn. Is there any way to fix this?

totool = script.Parent
cooldown = false
character = game.Players.LocalPlayer.Character
player = game.Players.LocalPlayer



local function weldBetween(a, b)
    --Make a new Weld and Parent it to a.
    local weld = Instance.new("ManualWeld", a)
    weld.Part0 = a
    weld.Part1 = b
    --Get the CFrame of b relative to a.
    weld.C0 = a.CFrame:inverse() * b.CFrame
    --Return the reference to the weld so that you can change it later.
    return weld
end


tool.Activated:connect(function()
	if cooldown == false then
		
		rightArm = character["Right Arm"]:Clone()
		rightArm.Name = "CRight Arm"
		rightArm.Parent = character
		
		
		x = game.Lighting.AnimationFixScript2:Clone()
		x.Parent = rightArm
		
		weldBetween(rightArm,character["Right Arm"])
		cooldown = true
		game.Chat:Chat(player.Character.Head, "Chop Chop Punch!")
		Animation = tool.Animation
		AnimationTrak = tool.Parent.Humanoid:LoadAnimation(Animation)
		AnimationTrak:Play()
		candamage = true
		rightArm.touched:connect(function(Target)
			if candamage == true then
	
				if Target.Parent.Name ~= character.Name and candamage == true then
							
					candamage = false
					Target.Parent.Humanoid.Health = Target.Parent.Humanoid.Health - 20
					candamage = false
					wait(2)
				end
			end

		end)
			wait(5)
			cooldown = false
	end
end)

3 comments

0

Could you explain the problem more?

0

Use a .touched event?

0

No like touched events don't work if you play a animation. The only way I know is to make the play turn while the animation is playing and they are touching a object. But what I'm asking is there any other way?

1 answer

What are you trying to do with the rightarm.touched?'

rightArm.touched:connect(function(Target) --This is the part of the code that is probably causing it
            if candamage == true then
                if Target.Parent.Name ~= character.Name and candamage == true then
                    candamage = false
                    Target.Parent.Humanoid.Health = Target.Parent.Humanoid.Health - 20
                    candamage = false
                    wait(2)
                end
            end
        end)

What you did is create a script where it damages the player only if it hit his/her right arm. I think that might be your problem. Try changing it so something like,

torso.touched:connect(function(Target) --This is the part of the code that is probably causing it
            if candamage == true then
                if Target.Parent.Name ~= character.Name and candamage == true then
                    candamage = false
                    Target.Parent.Humanoid.Health = Target.Parent.Humanoid.Health - 20
                    candamage = false
                    wait(2)
                end
            end
        end)

This would activate if you hit their torso. Try to make a .hit statement and create an if statement to check to see if the parent of the part that was hit was the player (and obviously not the right arm).

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