尝试使用 'Connect' With Changed 事件索引 nil

Attempt to index nil with 'Connect' With Changed event

我有错误:

attempt to index nil with 'Connect'  -  Client - LocalScript:3

我试图做到这一点,以便在更新字符串值时,它会用它更新 GUI 文本

local status = game.Workspace.Status.Value

status.Changed:Connect(function()
    script.Parent = status
end)

我正在学习的教程:Youtube tutorial

这是一个本地脚本。

game.Workspace.Status 是字符串值。当您将 .Value 保存到变量中时,您并没有保留对 StringValue 本身的引用,而是将其值复制到变量中。

所以你解决了你的问题,你只需要你的变量指向 StringValue,而不是存储在它里面的字符串。

local status = game.Workspace.Status

status.Changed:Connect(function()
    script.Parent.Text = status.Value
end)