Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make another animation play if the player's hand comes in contact with another player?

Asked by 5 years ago
Edited 5 years ago

The first function works perfectly but the second function somehow breaks the first one when I test it out, what I want to happen is that while the animation is playing if by the end of the animation it starts Animation2 if it doesn't come in contact with another player but if it does come in contact with another player I want it to start Animation3. Any help?

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer 
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid") 
local Animation = Instance.new("Animation") 
Animation.AnimationId = "rbxassetid://2867339187" 
local Animation2 = Instance.new("Animation") 
Animation2.AnimationId = "rbxassetid://2867339668"
local Animation3 = Instance.new("Animation") 
Animation3.AnimationId = "rbxassetid://2867395453"
local track = Humanoid:LoadAnimation(Animation)
local track2 = Humanoid:LoadAnimation(Animation2)
local track3 = Humanoid:LoadAnimation(Animation3)
local OtherHumanoid = hit.Parent:FindFirstChild("Humanoid")


--Just finding the Particles--
local particle = Character:WaitForChild("LeftUpperArm"):WaitForChild("ParticleEmitter") 
local particle1 = Character:WaitForChild("RightLowerArm"):WaitForChild("ParticleEmitter") 
local particle2 = Character:WaitForChild("RightUpperLeg"):WaitForChild("ParticleEmitter") 
local particle3 = Character:WaitForChild("UpperTorso"):WaitForChild("ParticleEmitter")
local particle4 = Character:WaitForChild("LowerTorso"):WaitForChild("ParticleEmitter")


--Finds Hands--
local handl = Character:WaitForChild("LeftHand")
local handr = Character:WaitForChild("RightHand")


--Funtion That Starts Animation and Enables the Particles--
UserInputService.InputBegan:Connect(function(input, proc) 
    if not proc and input.KeyCode == Enum.KeyCode.T then
        particle.Enabled = true 
        particle1.Enabled = true
        particle2.Enabled = true 
        particle3.Enabled = true
        particle4.Enabled = true
        track:Play() 
        wait(0.35) 
        track:Stop()
    end 
end)

--If it's a player it switches to one animation and if it's not a player it switches to another animation--
handl.Touched:Connect(function(hit)
  if OtherHumanoid then
     track3:Play()
     wait(0.4)
     track3:Stop()
     particle.Enabled = false
     particle1.Enabled = false
     particle2.Enabled = false
     particle3.Enabled = false
     particle4.Enabled = false
   if not OtherHumanoid then 
     track2:Play()
     wait(0.45)
     track2:Stop()
     particle.Enabled = false
     particle1.Enabled = false
     particle2.Enabled = false
     particle3.Enabled = false
     particle4.Enabled = false
end
0
Bump songboy50 77 — 5y

Answer this question