【发布时间】:2022-01-05 04:40:20
【问题描述】:
所以基本上我想制作一款塔防游戏,我添加了一个按钮,点击后会在带有 AI 的塔/机器人中生成。 (脚本是本地的)尝试使用'leaderstats'索引 nil 总是让我出错。 (我知道这意味着游戏不知道leaderstats 是什么),我制作了一个脚本,在播放器内部创建了名为leaderstats 的文件夹,里面有硬币和其他东西,但它仍然不知道有一个leaderstats 文件夹。我也尝试了 FindFirstChild(),但它只是说尝试使用 'FindFirstChild' 索引 nil。谁能帮帮我?
local button = script.Parent
button.MouseButton1Click:Connect(function(player)
local spawner = game.Workspace.ts1
local money = player.leaderstats.Cash.Value
if money >= 250 then
money = money - 250
local clone = game.ReplicatedStorage.Allies.Guard:Clone()
clone.Parent = workspace
clone.HumanoidRootPart.CFrame = spawner.HumanoidRootPart.CFrame
else
if money <= 250 then
button.BackgroundColor3 = Color3.new(1, 0, 0)
button.Text = "Too Expensive"
wait(0.5)
button.Text = "Guard [250$]"
button.BackgroundColor3 = Color3.new(0.603922, 0.603922, 0.603922)
end
end
end)
【问题讨论】:
-
Attempt to index nil with 'leaderstats'. (I know that this means the game doesnt know what leaderstats is)- 不。这意味着player是nil