你好,
所以我会明白这一点..
每个人都知道,在Roblox中,您有一个ReplicatedStorage(用于客户端和服务器)和一个ServerStorage(仅用于服务器)。
所以我想将所有资产存储在ServerStorage中......你知道,因为如果他们尝试过,那么剥削者/黑客就无法看到ServerStorage。
然而,我的游戏具有虚拟世界......意味着客户端在任何给定时间都看到与其他客户端不同的对象,因此我不能仅从服务器脚本加载对象,因为每个人都会看到它。
接下来的问题:我是否可以设置一个远程函数,让客户端调用服务器,然后服务器返回一个模型对象或其位置或类似的东西?然后我可以使用客户端将模型加载到播放器的工作区吗?
^这样我可以安全地将我的重要游戏资产存储在serverstorage
中答案 0 :(得分:1)
您的问题的答案是“是的,你可以!”
首先,您将要在ReplicatedStorage中创建RemoteFunction。调用此RemoteFunction,'GetModel'
现在,我们将在StarterPack内部设置一个本地脚本。此本地脚本应具有以下代码:
local RS = game:GetService("ReplicatedStorage")
local RF = RS:WaitForChild("GetModel")
local model = RF:InvokeServer("ModelName") -- This code can go anywhere you'd like it to go. 'ModelName' is the name of the model you want to get.
print(model.Name) -- This will print the model's name.
好的,我们设置代码来调用远程功能。现在,让我们让RemoteFunction做点什么。我们将在ServerScriptService中创建一个服务器脚本。这是代码:
local RS = game:GetService("ReplicatedStorage")
local RF = RS:WaitForChild("GetModel")
RF.OnServerInvoke = function(player, modelName)
local model = game.ServerStorage:FindFirstChild(modelName)
if model == nil then
return nil
else
return model
end
end
这大部分都是基本代码,从你在问题中所说的,你似乎理解你很好。希望我能帮助你! :)