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

Any way to make better this OnTouch event animation?

Asked by 6 years ago

I'm trying to make an animation onTouch event, but I don't want to let the player move, so I made a command that changes the player walkspeed, but it is worst than before. The animation doesn't play properly, any help?

local Anim = script.Parent.Animation -- Animation
local debounce = false

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
        debounce = true
        hit.Parent:findFirstChild("Humanoid").WalkSpeed = 0
local AnimTrack = hit.Parent.Humanoid:LoadAnimation(Anim)
        AnimTrack:Play()
        wait(2.8) -- Seconds Before You Can Play Animation Again.
        debounce = false
       hit.Parent:findFirstChild("Humanoid").WalkSpeed = 16
    end
end)



0
Are you trying to make like a talking + animation NPC? Bazuxk 95 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I'm confused on what you mean when you say the animation doesn't play properly, so I'm assuming it doesn't play at all. It may be that FindFirstChild is not capitalized on lines 7 and 12? I've just tested the following modified code and it seemed to work fine for me:

local anim = script.Parent.Animation
local db = false

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and db == false then
        db = true
        humanoid.WalkSpeed = 0
        local animTrack = humanoid:LoadAnimation(anim)
        animTrack:Play()
        wait(animTrack.Length)
        humanoid.WalkSpeed = 16
        db = false
    end
end)

However, if it still doesn't work, try making sure that your script and animation are inside the part or if the animation Id is correct.

Hope this helps

0
Thanks! But looks like the player still moves when the animation is played. EletricSpade1569 0 — 6y
0
https://www.roblox.com/games/776703128/Find-The-Bloxikins-Official-Not-Released here is the place i'm making this thing, just go on the light gray part. EletricSpade1569 0 — 6y
Ad

Answer this question