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

Why doesn't anything happen when a player touches this brick?

They should perform an animation but at the moment nothing happens when the brick is touched.

function onTouched(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
	if h ~= nil then
		local anim = Instance.new("Animation")
		anim.AnimationId = "rbxassetid://29517689"
		anim:Play()
	end
end
script.Parent.Touched:connect(onTouched)

2 comments

1

You never load the animation.

1

How do I load the animation?

1 answer

✓ Accepted answer

You forgot to load your animation into the humanoid.

function onTouched(hit)
	local h = hit.Parent:findFirstChild("Humanoid")
	if h ~= nil then
		local anim = Instance.new("Animation")
		anim.AnimationId = "rbxassetid://29517689"
		local animLoad = h:LoadAnimation(anim) -- An animation has to be loaded into the humanoid
		animLoad:Play()
	end
end
script.Parent.Touched:connect(onTouched)

1 comment

1

Thank youu!!!

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