Hi there, I keep getting this error ServerScriptService.LongStickBuy:4: attempt to index nil with 'WaitForChild'
How would I go about debugging this? I obviously can’t use print to see what is going wrong. I’ve been stuck on this problem for about a day now. Also please share your debugging methods/tips.
Thanks.
ServerScript
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage:WaitForChild(“RemoteEvent1”)
local player = game.Players.LocalPlayer
local playerStats = player:WaitForChild(“leaderstats”)
local playerGold = playerStats:WaitForChild(“Gold”)
local function purchasFunc(player, item)
local gold = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Gold")
if playerGold.Value >= 100 and player.Owned.Value == false then
playerGold.Value = playerGold.Value - 100
end
end
remoteEvent.OnServerEvent:Connect(purchasFunc)
Hello! This is quite simple. I think that you are sending a RemoteEvent to the server, but with the argument either not defined, or created on the client, so the server just sees nil. Read this article for more info about Client and Server
First thing I’m noticing is that your variable is called “gold” but later in the script you refer to gold as the variable “playerGold” but “playerGold” is never declared anywhere.
If it’s a server script why are you getting the local player?
You cant get the localPlayer in a server script like this, this will only work in a localScript
Here again, I think you dont understand the client and server difference that’s why. May I suggest learning about it because if you dont understand, any explanation further will just confuse you