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

How can I make this onTouch?

Asked by 9 years ago

I need this to be on touch so when someone touches a part it will activate the script.

function onChildEntered(child)
    if game.Players:findFirstChild(child.Name) then
        if child:findFirstChild("Animate") then
            child.Animate:remove()
        end
    end
end
game.Workspace.ChildAdded:connect(onChildEntered)

2 answers

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
9 years ago

What CodeTheorem said, but it'd look more like this:

script.Parent.Touched:connect(function(hit)
    local plr = Game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    local anim = hit.Parent:FindFirstChild("Animate")
    if plr and anim then
        anim:Destroy()
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

You just have to change the Event that you are handling. Here's an example:

script.Parent.Touched:connect(function(hit)
    if game.Players:findFirstChild(hit.Name) then
        if hit:findFirstChild("Animate") then
            hit.Animate:remove()
        end
    end
end)

Answer this question