i am new to scripting and i was wondering why it said attempt to index nil with find first child when i typed this in.the problem is on the bold line.This is a regular script.
local stats = game.ServerScriptService.LeaderStats:FindFirstChild("leaderstats")
local Pmoney = stats:findFirstChild("Cash") local Pmulti = stats:findFirstChild("Multi") local Preb = stats:findFirstChild("Rebirths")
so i was wondering if any of you guys can help me. sorry if this is a easy solution im very new to scripting and barely know anything.
Well stats does not exist or the script executed before they loaded.
Solutions:
Use :WaitForChild()
, it waits for the instance to load.
Example:
local stats = game.ServerScriptService:WaitForChild"LeaderStats":WaitForChild("leaderstats") local Pmoney = stats:WaitForChild("Cash") local Pmulti = stats:WaitForChild("Multi") local Preb = stats:WaitForChild("Rebirths")
Other solution is that it just does not exist, check if you defined it right, for example it could be named "leaderStats" but you defined it as "LeaderStats" the L is capital so it could not find anything or it is located in ServerStorage but you typed in ServerScriptService
Last solution is that if it is a local script, you can not access serverscriptservice with it. There is replicatedStorage for it.
Hope this helps.