Game not detecting touched event

Viewed 7

I was trying to make a script for my NPC, that will place a bodyvelocity inside player that touched the glove that NPC Got in his hand, however it didn't do anything. I tried to make a touch event that will print something out when something touches the glove, but it didn't work too.

Code:

local cooldown = 0.7

activated = false
deb = false
slapped = false

local slapanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.SlapAnim)


    


while true do
    if activated == false and deb == false then
        deb = true
        activated = true
        slapanim:Play()
        wait(0.3)
        activated = false
        wait(cooldown-0.3)
        slapped = false
        deb = false
    end
end


    --[[if activated == true and slapped == false and hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= script.Parent.Parent then
        print('b')
        slapped = true
        script.Parent.Hand.Slap:Play()  
        hit.Parent.Humanoid.Sit = true
        local velocity = Instance.new('BodyVelocity', hit.Parent.HumanoidRootPart)
        velocity.MaxForce = Vector3.new(3,3,3) *math.huge
        local dir = (hit.Parent.HumanoidRootPart.CFrame.Position - script.Parent.Parent.HumanoidRootPart.CFrame.Position)
        velocity.Velocity = (dir +Vector3.new(0,2,0)).Unit *25
        local rot= Instance.new('BodyAngularVelocity', hit.Parent.HumanoidRootPart)
        rot.AngularVelocity = Vector3.new(1,1,1) *math.pi *2
        rot.MaxTorque = Vector3.new(2,2,2) *math.huge
        rot.P = 5000
        
        game:GetService('Debris'):AddItem(velocity, 0.3)
        game:GetService('Debris'):AddItem(rot, 0.3)
        wait(0.3)
        hit.Parent.Humanoid.Sit = false
    end]]
script.Parent.Hand.Touched:Connect(function(hit)
    print(hit.Parent.Name)
end)
0 Answers
Related