when I start testing the game in roblox studio, everything is normal, but when I go to the normal game there are a lot of errors I can not understand how I can fix them (I do not understand either something is not loaded or something else).
Just use FindFirstChild
… Either your leaderstats exists or not, so there’s no reason for you to add a wait especially if its not the client
then i have a new problem with FindFirstChild
essentially what is happening is that the game cannot find “leaderstats” under your player. 2 possibilities for this
- Your leaderstats folder did not load in time before :WaitForChild was called, thus it cannot find something that hasnt existed yet
- You misnamed the leaderstats folder, it has to be case sensitive
Use the method (FindFirstChild
) to check for the folder then use it again to check for other things. This method will remove errors
can u send the script
use ```
before you paste your script block and paste it again at the end of the script so it looks like this
code
local Cash = script.Parent
local RS = game:GetService("ReplicatedStorage")
local short = require(RS.Modules.Utilities.Short)
local player = game.Players.LocalPlayer
local leaderstats = player:FindFirstChild("leaderstats")
local meteorCash = leaderstats:FindFirstChild("MeteorCash")
script.Parent.Text = "$" .. short.en(meteorCash.Value)
meteorCash.Changed:Connect(function()
script.Parent.Text = "$" .. short.en(meteorCash.Value)
end)
RS.Events.GiveTheCash.OnClientEvent:Connect(function(value)
Cash.Text = "$" .. short.en(value)
end)
``` a new error occurs in this script and the old one that was with WaitForChild
make sure the leaderstats folder is named “leaderstats” and its under your player. You can check by playtesting and click the drop down menu on your character in explorer tab.
The reason why it says “attempt to index nil with FindFirstChild” is because leaderstats is returning nil.
leaderstats is there, most likely that the leaderstats folder itself takes longer to load and it does not find it, because when there was WaitForChild everything worked (only in the studio) in the game itself in roblox did not work, or it worked but over time an error kept appearing.
Maybe try this? The only difference is that it times out and returns nil
local leaderstats = player:FindFirstChild("leaderstats") or player:WaitForChild("leaderstats", 5)
local meteorCash = leaderstats:FindFirstChild("MeteorCash") or leaderstats:WaitForChild("MeteorCash", 5)
I just ignore them, and its a warn not an error
the studio is waring you that WaitForChild() could wait forever
you should only use WaitForChild() if you want to define a thing that is not here when the script run
(like you will create it later or smth)
so yeah
try to add task.wait(2) in the start
and keep using FindFirstChild()
this should work
cuz the script run before even the player load
so waiting 2-4 seconds i am perrty sure will fix the scirpt
Can you send a larger screenshot? It’s more important to see the parents of the folder than the children in this case.
thank you for pointing out the smart thing that it’s just a warning, I solved the problem.
I have another question I always have to wait 2-4 seconds when I enter the game or it can be changed?
can you give more info?
1- is the things you are trying to find with FindFirstChild() is created by another script or its there?
2- where is the things you are trying to find located?
and i will help you
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.