My script is:
script.Parent.MouseButton1Click:Connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Sword") local price = 100 local Players = game:GetService("Players") local player = Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Money.value >= price then stats.Money.value = stats.Money.value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)
the whole error says:
Players.HamsterxDD.PlayerGui.ScreenGui.Frame.TextButton.Script:7: attempt to index nil with 'WaitForChild'
If anyone has a simple solution please tell me about it. I'm a beginner and i'm still practicing, any help will be appreciated.
script.Parent.MouseButton1Click:Connect(function(player) --You forgot to write that there, so "player" was nil. local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Sword") local price = 100 local Players = game:GetService("Players") local stats = player.leaderstats -- We don't need "WaitForChild" there because when they click it, everything is loaded. if stats.Money.value >= price then stats.Money.value = stats.Money.value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)
Hope this helped!