Index nil with WaitForChild, Why is this?

  1. What do you want to achieve? I want it so when i rebirth it rebirths and doesnt say this

  2. What is the issue?

  3. **What solutions have you tried so far?**No every other one is different then mine makes sense but still

Im making a game and if you could answer this that would be gladly appreciated but its where you punch objects and get resources and every time you get 25 you can rebirth or upgrade your damage

local screen = game.StarterGui.Rebirth
local button = script.Parent

button.MouseButton1Click:Connect(function(player)
	local resources = player:WaitForChild("leaderstats"):WaitForChild("Resources")
	local rebirths = game:WaitForChild("leaderstats"):WaitForChild("Rebirths")
	
	if resources.Value >= 25 then
		resources.Value -= 25
		rebirths.Value += 1
	end
end)

Thanks For Helping!

I’ll assume this script is inside a click detector.
That error is trying to say that you’ve indexed something that doesn’t exists w WaitForChild so since player isnt nil player:WaitForChild(“leaderstats”) must be returning nil in other words leaderstats doesn’t exists make sure you’ve written its name correctly.

Its in startergui in screen gui in a frame in a text button

.MouseButton1Click doesnt return anything you have to do this instead

local screen = game.StarterGui.Rebirth
local button = script.Parent

local Player = game:GetService("Players").LocalPlayer --Use this before the event
local LeaderStats = Player:WaitForChild("leaderstats")
local Resources = LeaderStats:WaitForChild("Resources") --Its not like these get deleted so no reason to get em again and again every time the button gets pressed
local Rebirths = LeaderStats:WaitForChild("Rebirths")

local function OnButtonPress()
	if Resources.Value >= 25 then
		Resources.Value -= 25
		Rebirths.Value += 1
	end
end
button.MouseButton1Click:Connect(OnButtonPress)

Oh sorry i didnt understand something does exist its in the player 3 values are in the player one leaderstats in leaderstats there is Resources and rebirths

This is a local script right?
Also could you just take a screen shot of your explorer and send it?

Sure here it is

Heres the full explorer

Do you need the workspace might take awhile though?

Could you show where the values are etc.?

Yea these are only important things
image

Could you use this and let me know if there are any errors?

local Player = game:GetService("Players").LocalPlayer
local screen = Player.PlayerGui:WaitForChild("Rebirth")
local button = script.Parent

local LeaderStats = Player:WaitForChild("leaderstats")
local Resources = LeaderStats:WaitForChild("Resources") --Its not like these get deleted so no reason to get em again and again every time the button gets pressed
local Rebirths = LeaderStats:WaitForChild("Rebirths")

local function OnButtonPress()
	if Resources.Value >= 25 then
		Resources.Value -= 25
		Rebirths.Value += 1
	end
end
button.MouseButton1Click:Connect(OnButtonPress)

I’m not sure if I understand what you’re trying to do as updating values through a local wont be visible to the server. If you’re trying to send information to the server about what a player has etc. you’re suppose to be using remote events.

Well Thanks for helping idk how to use it though

Replace the script snippet you’ve shown with it is what I meant.

Ik i did and it works now thanks