Provide an overview of:
- What does the code do and what are you not satisfied with?
The code is sopposed to a mob spawned where it keep spawning NPCs and respawning when it is less than 10, when you destroy one you earn cash. I can’t seem to get the leadstats which is under players
The first method I tried ended with and error of “(attempt to index nil with ‘FindFirstChild’)”. I tried looking at the other forums but no luck there. The second method I tried putting a yeild so that they could load but it didn’t work
First Script:
local character = game.Players
local player = game.Players:GetPlayerFromCharacter(character)
local ServerStorage = game:GetService(“ServerStorage”)
local leaderstats = player:FindFirstChild(“leaderstats”)local MOB_RIG = ServerStorage:FindFirstChild(“Rig”)
local MAX_AMOUNT = 10
local TEST_FOLDER = workspace.TestFolder
local SPAWN_PART = workspace.MobSpawn
local CashAmount = MOB_RIG.CashAmountlocal function SpawnMob()
local clone = MOB_RIG:Clone()
local cloneHumanoid:Humanoid = clone:FindFirstChild(“Humanoid”)
local cloneHumanoidRootPart = clone:FindFirstChild(“HumanoidRootPart”)cloneHumanoidRootPart.Position = SPAWN_PART.Position
clone.Parent = TEST_FOLDERcloneHumanoid.Died:Once(function()
SpawnMob()
CashAmount.Cash.Value += 100
end)
endfor _ = 1, MAX_AMOUNT do
SpawnMob()
end
Second Script:
local players = game.Players
local leaderStats = players:WaitForChild(“leaderstats”,5)
local cashAmount = 100
local ServerStorage = game:GetService(“ServerStorage”)local MOB_RIG = ServerStorage:FindFirstChild(“Rig”)
local MAX_AMOUNT = 10
local TEST_FOLDER = workspace.TestFolder
local SPAWN_PART = workspace.MobSpawnlocal function SpawnMob()
local clone = MOB_RIG:Clone()
local cloneHumanoid : Humanoid = clone:FindFirstChild(“Humanoid”)
local cloneHumanoidRootPart = clone:FindFirstChild(“HumanoidRootPart”)cloneHumanoidRootPart.Position = SPAWN_PART.Position
clone.Parent = TEST_FOLDERcloneHumanoid.Died:Once(function()
SpawnMob()
cashAmount = leaderStats:WaitForChild(“Cash”, 5).Value
end)
endfor _ = 1, MAX_AMOUNT do
SpawnMob()
end