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

How do i make a Animation Play When A Part Is Touched?

Hello so i am trying to do this script ~~~~~~~~~~~~~~~~~

local brick = script.Parent
local debounce = false


function onTouch(plr)
	if not debounce then
		local hum = game.Players:GetPlayerFromCharacter(plr.Parent)
		local humanoid = plr.Parent:FindFirstChild("Humanoid")
		local anim_load = humanoid:LoadAnimation(script.Parent.Animation)
		local current = anim_load
		current:Play()
		debounce = true
	end
	wait(3)
	debounce = false
end
brick.Touched:connect(onTouch)**** So anyways the script wont work, and the script is in a part and when i touch it i want a animation plays. Please reply

1 comment

0

Is this a local script or a normal script?

1 answer

✓ Accepted answer

do this inside a serverscript inside the part

local debounce = false
-- Inside a serverScript btw
part.Touched:Connect(function(hit)
	if not debounce then
		if hit.Parent:FindFirstChild("Humanoid") then
			debounce = true
			local humanoid = hit.Parent.Humanoid -- Getting the humanoid
			humanoid:LoadAnimation(youranimationhere):Play() -- Playing the animation
			wait(2)
			debounce = false
		end
	end
end)

1 comment

0

Thanks! It worked! sorry for late reply :P

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