I got a module script for my tower shop and i added a new item and wanted to use the value i created inside the player and got attempt to index nil with WaitForChild. Some insight would be great. but heres my script
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local TowerShop = {
["Bronze Robloxian"] = {
["Name"] = "Bronze Robloxian",
["ImageAsset"] = "rbxassetid://11624666096" ,
["Price"] = 800 ,
["Description"] = "Bronze Robloxian will buff the damage of towers around it. When upgraded to gold damage is fully doubled",
["Event"] = true,
},
["Blue Robloxian"] = {
["Name"] = "Test",
["ImageAsset"] = "rbxassetid://" ,
["Price"] = 0,
["Description"] = "Desc",
["Event"] = player:WaitForChild("Even").Value,
}
}
return TowerShop
The error “attempt to index nil with WaitForChild” occurs when you try to access a property or method of an object that is nil (meaning it does not exist). In this case, the object is the result of calling WaitForChild() on the player object, and the property you are trying to access is Value .
To fix the error, you can either check that the object you are trying to access exists before trying to access it, or you can use a different method to access the value that you want.
A way to do this is FindFirstChild() method instead of WaitForChild() , and check for the existence of the child before trying to access its value. Alternatively, you can use the try() function to wrap the WaitForChild() call and catch any errors that may occur.
You meant to say: You can’t get the local player on the server, only on the client.
ModuleScripts have access to LocalPlayer as long as it’s being run from a local script.
Thanks for all the help. I ended up getting it to work. I just did it differently but got it working perfectly. Created a folder in replicated storage same name as the player and then in my local script i had it only show the towers that were in said players folder. Works out flawlessly