Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Seraine 103
7 years ago

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)
1
You never load the animation. User#11440 120 — 7y
1
How do I load the animation? Seraine 103 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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
Thank youu!!! Seraine 103 — 7y
Ad

Answer this question