我正在努力寻找一种好方法 link 我的服务器到我的 Roblox 游戏

I am struggling to discover a good method to link my server to my Roblox game

昨天我设置了一个 Ubuntu 服务器来 运行 一些游戏外脚本与游戏内脚本一起工作。我在我的游戏编辑器中启用了 HTML 调用和第三方访问。我还查看了对象浏览器,寻找可能在 get 和 post 请求中使用的对象。我想出了一些代码,但它完全不起作用。

local UserId = game.Players.LocalPlayer
local mining = UrlEncode("http://216.128.0.0:34648/")

for mining in Connect(function() 
        
            
            
        
    getAsync(mining.."/"..UserId)
    PostAsync(mining.."/"..UserId)
    end)
    
     do JSONEncode()
    
    JSONDecode()
    
Any advice or help would be appreciated. Thanks.

首先,如果您还没有启用 HTTP:

iirc,您不能从客户端发送 http 请求:您必须使用服务器脚本。这意味着您无法通过 LocalPlayer 获取播放器。我提供了一个 POST request 的示例,它使用 JSON 发送数据。

ServerScriptService 中的脚本:

local HttpService = game:GetService("HttpService")
local serverURL = "http://216.128.0.0:34648/mining"

function mine(player)
    local arguments = {
        ["userID"] = player.UserId,
        ["name"] = player.Name
    }
    
    local response = HttpService:PostAsync(serverURL, HttpService:JSONEncode(arguments), Enum.HttpContentType.ApplicationJson)
    local responseData = HttpService:JSONDecode(response) --assuming the response is in JSON
    print(responseData)
end

game.Players.PlayerAdded:Connect(mine)

我不知道你的服务器是如何构建的,所以你可能需要解决这个问题。有一个很棒的 wiki page,其中包含更多信息和示例。