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

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

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?

1 comment

0

Put "hit" inside the ouch function and replace the "ouchs" in the functions with "hit".

2 answers

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)

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)

2 comments

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

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.

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