Hey, I’m having trouble identifying what’s wrong with this. Basically when you touch the part, It’ll change your animation but for some reason it won’t work here.
Here’s the script:
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if human then
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://6007672361"
end
end
script.Parent.Touched:Connect(onTouched)
local animation = character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://6007672361"
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if human then
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
animation:Play()
end
end
script.Parent.Touched:Connect(onTouched)
local humanoid = rig:FindFirstChild(“Humanoid”)
local animator = humanoid:WaitForChild(“Animator”)
You can have an animation inside this script in which you can change the animation ID
local animation = script:WaitForChild(“Animation”)
local loadedAnimation = animator:LoadAnimation(animation)
loadedAnimation:Play()
So…
Here is my implementation of this code in your provided script:
function onTouched(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if human then
local animator = human:WaitForChild(“Animator”)
local animation = Instance.new(“Animation”)
animation.AnimationId = “http://www.roblox.com/asset/?id=507771019”
local loadedAnimation = animator:LoadAnimation(animation)
loadedAnimation:Play()
end
end
script.Parent.Touched:Connect(onTouched)
API References:
Edit: I did this on mobile so the quotations are messed up
local touchPart = script.Parent -- your touch part
local animationId = 6007672361 -- your custom animation id
touchPart.Touched:Connect(function(hit)
local char = hit.Parent
if char then
local animate = char:FindFirstChild("Animate")
if animate then
animate.walk.WalkAnim.AnimationId = "rbxassetid://".. animationId
animate.run.RunAnim.AnimationId = "rbxassetid://".. animationId
end
end
end)
Once you touch the part, it should change your walk animation to custom one, and also make sure that your animation has proper priority set.
I think its not working due to you are using deprecated methods to get the character, and its a LocalScript, so theres no point to check what humanoid has touched the part, it will always be your humanoid.
local Player = game:GetService(“Players”).LocalPlayer or game:GetService(“Players”).PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait() or workspace:FindFirstChild(Player.Name)
local Humanoid = Character:WaitForChild(“Humanoid”)
function onTouched(hit)
if (Humanoid and Humanoid.Health > 0) then
local Animate = Character:FindFirstChild("Animate")
if Animate then
Animate:FindFirstChild("walk").WalkAnim.AnimationId = "rbxassetid://6007672361"
else
warn("Animate script wasn't found on " .. Character:GetFullName())
end
end
end
script.Parent.Touched:Connect(onTouched)
Try that, i just think you should use a Server Script instead a Local one.