解决方法:尝试使用"已输入"索引 nil



所以基本上,脚本应该在介绍屏幕消失后加载文本,不确定它有什么问题,因为它在2014年工作:/

代码:

if true then
script.Parent.slowsleigh:Play()
fadegui({intro.load},{0},{1},30)
wait(1)
local titles = intro.titles
local text1 = titles.title1.Text
local text2 = titles.title2.Text
local text3 = titles.title3.Text
local text4 = titles.title4.Text
if GameData.entered == 1 then
text1 = "And you came back."
text2 = "You can't change the past."
text3 = "Pathetic."
end
titles.title1.Text = ""
titles.title2.Text = ""
titles.title3.Text = ""
titles.title4.Text = ""
--[
titles.title1.Visible = true
for i = 1, #text1 do
titles.title1.Text = string.sub(text1,1,i)
wait(0.05 + math.random(-5,10)/200)
end

下面是ServerScriptServices

里面的脚本
local data = game:GetService("DataStoreService"):GetGlobalDataStore()
local dataVersion = 2
local func = Instance.new("RemoteFunction",workspace)
func.Name = "GetData"
function func.OnServerInvoke(player)
local store = data:GetAsync(tostring(player.UserId))
return store
end
local set = Instance.new("RemoteEvent",workspace)
set.Name = "SetData"
set.OnServerEvent:connect(function(player,newData)
local store = data:GetAsync(tostring(player.UserId))
for i,v in pairs(newData) do
store[i] = v
end
data:SetAsync(player.UserId, store)
end)

错误:

17:48:57.908  Players.Trl0_P90.PlayerGui.maingui.mainscript:758: attempt to index nil with 'entered'  -  Client - mainscript:758

GameData为nil时,错误告诉您正在尝试访问GameData.entered

从您共享的代码来看,您的问题似乎是您正在从数据存储访问数据,而没有考虑到它可能不存在的事实。看一下GlobalDataStore的文档:GetAsync():

这个函数返回所提供的键的最新值和一个DataStoreKeyInfo实例。如果键不存在或最新版本被标记为已删除,则两个返回值都将为nil。

这可能是由于新玩家加入,没有默认数据造成的。你可以做的一件事是设置一些默认数据以防有一个新播放器:

local func = Instance.new("RemoteFunction",workspace)
func.Name = "GetData"
function func.OnServerInvoke(player)
local store = data:GetAsync(tostring(player.UserId))
-- if there is no data, it might be a new player!
-- provide some new player data
if not store then
store = {
entered = 1,
foo = true,
bar = "blah",
}
end
return store
end

这样,函数将始终返回正确的形状数据。

最新更新