存在时尝试使用 FindFirstChild 索引 nil

问题描述 投票:0回答:0

Players.(My Name).Backpack.Tool.Script:6: 尝试用'FindFirstChild'索引nil

这就是 Player 层次结构的样子 Image

local PlayerStatManager = require(game.ServerScriptService.PlayerStatManager)
local tool = script.Parent
local plname = script.Parent.Parent.Parent.Name
local player = game.Players:FindFirstChild(plname)
local activated = true
local UI = script.Parent.Parent.Parent:FindFirstChild("PlayerGui"):FindFirstChild("LC"):FindFirstChild("Text")

local function AddXP()
    if activated == true then
        UI.text = "+5 Experience"
        UI.TextTransparency = 0
        PlayerStatManager:ChangeStat(player, "Experience", 5)
    else 
        if activated == false then
            wait(1)
            activated = true
        end
    end
end


tool.Activated:Connect(function()
    AddXP()
end)
tool.Equipped:Connect(function() 
        UI.Text = "Equipped"
        UI.TextTransparency = 0
end)

我找不到为什么它不起作用 我尝试使用播放器变量、parent 和 findfirstchild。 在测试时,它说它存在,但我似乎无法弄清楚为什么它不起作用。

lua roblox
© www.soinside.com 2019 - 2024. All rights reserved.