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

How to change animation on touch?

function OnTouch(hit)
game.Players.LocalPlayer.Character.Anima.run.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=4958225000"
end

script.Parent.Touched:connect(OnTouch)

Error: error: Workspace.Knight.Button.Animation:2: attempt to index nil with 'Character' (I asked the discord, I wanted to see if I can get a different answer here too)

3 comments

0

all of that is in a script

0

localscript?

0

first you have to check if it is a character or not

1 answer

✓ Accepted answer

(This might not be fitting specifically for your case but this is some issues I saw)

First off, you're not checking if the thing that touched the part is even a character, so it might touch a random workspace object and attempt to find the "character" of that...

Second off, you don't need to do that long path to the character, you can just get the part's parent (after you've confirmed it is indeed a character)

function OnTouch(hit)
	local humanoid = hit:FindFirstChild("Humanoid")
	if humanoid then
		hit.Parent:WaitForChild("Anima").run.WalkAnim.AnimationId = "http://www.roblox.com/asset/?id=4958225000"
	end
end

script.Parent.Touched:Connect(OnTouch)

(also using :Connect instead of :connect is recommended)

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