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

OnTouch Tycoon Door Script Flawing?

function onTouched(hit)
local owner = script.Parent.Parent.Parent.Parent.Owner ---(The owner is a part value)
local h = hit.Parent:findFirstChild("Humanoid")
if (h ~= nil) then
	if h.Parent.Name == owner.Value or
		 owner.Value ~= nil then 
		print ("Ok")
		else h.Health = 0
	end
end
end

script.Parent.Touched:connect(onTouched)

Anyone know how to fix?

2 comments

1

Nope. Heck we don't even know what the problem is. Maybe... Just maybe.... You ought to tell us what is happening.... Don't you think???

0

everytime I see findFirstChild I think feemodel.

1 answer

I have fixed up your script, im not sure what exactly was causing the error but I removed some unnecessary code, and added another check.

function onTouched(hit)
	local owner = script.Parent.Parent.Parent.Parent.Owner ---(The owner is a part value)
	local h = hit.Parent:findFirstChild("Humanoid")
	if (h ~= nil) then
		if hit.Parent.Name == owner.Value then
			print("Ok")
			else h.Health = 0
		end
	end
end

script.Parent.Touched:connect(onTouched)

If it does not work, then it might just be that the path for the variable "owner" is incorrect.

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