Hiya! In the script i have, I was trying to make an owner's only door. only problem is... when my script describes the variable of tycoon on line 14, on line 15 the script tells me it has a nil value. Help?
dad = script.Parent
door = dad.Parent
owner = door.Parent.Owner
local active = 0
function onTouched(part)
local human = part.Parent:findFirstChild("Humanoid")
if human ~= nil and active == 0 then
active = 1
local player = game.Players:findFirstChild(part.Parent.Name)
if player ~= nil then
if owner.Value == "" then
local tycoon = player:findFirstChild("Tycoon") -- describes tycoon
if tycoon.Value == 0 then -- where error eccours
tycoon.Value = 1
owner.Value = player.Name
local message = Instance.new("Message")
message.Text = "You now own this tycoon!"
message.Parent = player
wait(3)
door.Name = "Tycoon Owner: " .. owner.Value
message:remove()
else
local message = Instance.new("Message")
message.Text = "You already own another tycoon!"
message.Parent = player
wait(3)
message:remove()
end
end
end
end
active = 0
end
dad.Touched:connect(onTouched)
Here's what the output says.
10:00:49.307 - Workspace.MrNiceGuy's Beginner Tycoon Kit.Tycoon.This Tycoon has no owner..OwnerDoor.[MNG]-OwnerScript:15: attempt to index local 'tycoon' (a nil value)

2 comments
your using "findfirstchild" which doesn't guarentee it will return an object, use "waitforchild" instead
also its "FindFirstChild" not "findFirstChild"