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

Why does an error keep popping up?

I keep getting the error "Workspace.berezaa's Tycoon Kit.Tycoons.Bright blue.PurchasedObjects.Build:10: attempt to index global 'h' (a nil value)"

found1 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Dropper1")
builder1 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut1")
builder2 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut2")
builder3 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut3")
h = builder1:findFirstChild("Peter" or "Carson" or "Hunter" or "Alex" or "Joe" or "Bob" or "Michael" or "Colt" or "Kristopher" or "Reed")

  if found1 then
	if builder1.Available.Value == true then
		builder1.Available.Value = false
		h.Torso.CFrame = CFrame.new(found1.disap.e.Position.x,found1.disap.e.Position.y,found1.disap.e.Position.z +2.66)
		found1.disap.Drop.Transparency = 1
		found1.disap.Drop.CanCollide = false
		found1.disap.q.Transparency = 1
		found1.disap.q.CanCollide = false
		found1.disap.w.Transparency = 1
		found1.disap.w.CanCollide = false
		found1.disap.e.Transparency = 1
		found1.disap.e.CanCollide = false
		found1.disap.r.Transparency = 1
		found1.disap.r.CanCollide = false
		wait(found1.IdleTime.Value)
--This script continues, just shortening it for the main problem.

1 answer

✓ Accepted answer

You could try using a for loop to check rather than :FindFirstChild().

found1 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Dropper1")
builder1 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut1")
builder2 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut2")
builder3 = script.Parent.Parent.PurchasedObjects:FindFirstChild("Hut3")

local h
for _, v in pairs (builder1:GetChildren()) do
	local names = {
	["Peter"] = true,
	["Carson"] = true,
	-- etc.
	}
	if names[v.Name] ~= nil then
		h = v
		break
	end
end

  if found1 then
    if builder1.Available.Value == true then
        builder1.Available.Value = false
        h.Torso.CFrame = CFrame.new(found1.disap.e.Position.x,found1.disap.e.Position.y,found1.disap.e.Position.z +2.66)
        found1.disap.Drop.Transparency = 1
        found1.disap.Drop.CanCollide = false
        found1.disap.q.Transparency = 1
        found1.disap.q.CanCollide = false
        found1.disap.w.Transparency = 1
        found1.disap.w.CanCollide = false
        found1.disap.e.Transparency = 1
        found1.disap.e.CanCollide = false
        found1.disap.r.Transparency = 1
        found1.disap.r.CanCollide = false
        wait(found1.IdleTime.Value)
--This script continues, just shortening it for the main problem.

2 comments

0

Bad answer. You just lost a subscriber.

0

Gonna go cry myself to sleep now

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