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

Sit on touch script won't work, attempts to index a global function value?

Asked by 5 years ago
function ouch()
if ouch.Parent:FindFirstChild("Humanoid") then
    ouch.Parent.Humanoid.Sit=true
end
end
script.Parent.Touched:Connect(ouch)

Pretty new to scripting, so I'm not the best at doing this. What should I change here?

0
Put "hit" inside the ouch function and replace the "ouchs" in the functions with "hit". CaptainD_veloper 290 — 5y

2 answers

Log in to vote
0
Answered by
xEmmalyx 285 Moderation Voter
5 years ago

The reason for this is ouch.Parent is a function, functions don't have parents. What you should be doing is this...

function ouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Sit=true
    end
end

script.Parent.Touched:Connect(ouch)
Ad
Log in to vote
0
Answered by 5 years ago

A cleaner way to do this would be:

script.Parent.Touched:connect(function(ouch)
    if ouch.Parent:FindFirstChild("Humanoid") then
        ouch.Parent.Humanoid.Sit = true
    end
end)
0
Erm. He hasn't defined the ouch function, so you wouldn't be using that parameter and you forgot to add the hit, because he has to find the hit.Parent, not the ouch.Parent, since you can't find Humanoid from a function. Just saying some people might downrep this post because it happened to me once, so be careful and edit what you said, fixing it up. Okie have a good day/night :D TheOnlySmarts 233 — 5y
0
The way he did the function requires that, with the way I did it, the object is already there, you just need to call it. I usually name it hit, but in this case I used ouch. I don't think it matters what it's named. ii_FireDev 10 — 5y

Answer this question