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

Any way to make better this OnTouch event animation?

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)



1 comment

0

Are you trying to make like a talking + animation NPC?

1 answer

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

2 comments

0

Thanks! But looks like the player still moves when the animation is played.

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.

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