Index nil with with FindFirstChild?

Are you sure it has a BillboardGui that is named “BillboardGui”? Because everything seems fine.

Yeah, I am 1000000% sure. I checked all the instances names.

for _,v in pairs(block:GetChildren())
  if v.Name == "Green" then
v:Clone()
v.Parent = workspace
end

No, but here it is. image

Could you share a studio file so I can take a look? Or else just export the relevant parts to a new file?

Alright, here you go. ForPanther.rbxm (7.8 KB)

For some or the other reason, The looping also clones all the other instances inside the folder. image image

I had a look and I couldn’t replicate the error you have. The only error I found came from you passing reward as the first parameter of the Green_Block function. After I removed that it worked fine.

function timeBlock:Green_Block()

Oh, lemme look into that if that’s causing the issue

Oh yeah I just saw in the original post you passed both block and reward as parameters in the function. That’s definitely going to be the reason it isn’t working. When you use OOP functions you’re basically resetting those variables to mean something else when you pass them like that. Since they’re already predefined in that script you don’t need to pass them anyway.

Still gives me billboardgui as a nil value.

And you’re doing it like this?

local timeBlock = {};

local reward = math.random(100, 200)
local block_ = game:GetService("ReplicatedStorage"):WaitForChild("RewardParts"):WaitForChild("Green"):Clone()

for _, part in ipairs(block_:GetChildren()) do
    print(part.Name)
end 

function timeBlock:Green_Block()
    local randomX = math.random(-96, -44);
    local randomZ = math.random(-153, 131);
    
    block_:WaitForChild("BillboardGui").Reward.Text = (reward .. " time");
    block_.Parent = workspace;
    block_.Position = Vector3.new(randomX, -1, randomZ);    

    block_.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if (player ~= nil) then
            player.leaderstats.Time.Value += tonumber(reward)
            block_:Destroy()
        end
    end)
end

return timeBlock;

Oh yeah, that’s changed, since I knew that would cause the issue too.

Oh wow, its fixed. What was the main issue though? that I couldn’t figure out?

I’m really not sure. If you didn’t pass the variables as parameters then it’s a bit of a mystery.

1 Like

Anyways, Thank you for putting your time and willing to help me, I really appreciate that! :slightly_smiling_face:

1 Like