Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

i have error:attempt to index nil with ''WaitForChild? [closed]

Asked by 4 years ago

i want to make shop but this error messes up everything. Help PLS!!!!

script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Stick") local price = 10 -- Change Your Price Here local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats")

if stats.Money.Value >= price then -- Change the Money to your Currency Name stats.Money.Value = stats.Money.Value - price local cloned = item:Clone() local cloned = item:Clone() cloned.Parent = player.Backpack cloned.Parent = player.StarterGear end end)

local stats = player:WaitForChild("leaderstats") it is line with error

0
Next time, present your code in codeblocks. DemonHunterz6 35 — 4y

Closed as Too Broad by JesseSong, marine5575, and youtubemasterWOW

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 4 years ago

It's because you haven't created an instance to actually insert the leaderstats into the player. You are trying to wait for something that isn't there.

Go to this article for help on creating leaderstats:

https://developer.roblox.com/en-us/articles/Leaderboards

0
Wouldn’t that mean he would get an Infinite Wait instead? zboi082007 270 — 4y
Ad