首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请求的模块在加载时出错-服务器-数据:11

请求的模块在加载时出错-服务器-数据:11
EN

Stack Overflow用户
提问于 2022-07-14 22:05:33
回答 2查看 532关注 0票数 -1

是的,所以,我正在编写一个Roblox游戏,这个脚本每次都会出错,我甚至重新启动了roblox工作室来尝试修复它,但是它没有工作,我试着乱搞代码,但我找不出答案,有人能帮我吗?

剧本:

代码语言:javascript
复制
local PetModule = require(ServerModules.PetModule)

模块代码:

代码语言:javascript
复制
local module = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage") 

local Pet = ReplicatedStorage.Pet

function module.EquipPet(Player, PetName)
    local PetModel = Pet:FindFirstChild(PetName)
    if PetModel then
        PetModel = PetModel:Clone()
        PetModel.Parent = workspace.Pet:FindFirstChild((Player.Name))
        if Player then
            local Character = Player.Character
            if Character then
                if not Character.HumanoidRootPart:FindFirstChild("PetAttachments") then
                    local PetAttachments = Instance.new("Folder")
                    PetAttachments.Name = "PetAttachments"
                    PetAttachments.Parent = Character.HumanoidRootPart


                    local PetAttachments = Character.HumanoidRootPart:FindFirstChild("PetAttachments")
                    if PetAttachments then
                        local att0 = Instance.new("Attachment")
                        att0.Name = "Attachment1"
                        att0.Position = PetModel:FindFirstChild("AttachmentPosition").Value
                        att0.Parent =Character.HumanoidRootPart

                        local att1 = Instance.New("Attachment")
                        att1.Name = "Attachment2"
                        att1.Parent = PetModel.PrimaryPart

                        local AlignPosition = Instance.new("AlignPosition")
                        AlignPosition.Attachment0 = att0
                        AlignPosition.Attachment1 = att1
                        AlignPosition.RigidityEnabled = false
                        AlignPosition.MaxForce = PetModel.MaxForce.Value
                        AlignPosition.Responsiveness = PetModel.Responsiveness.Value
                        AlignPosition.Parent = PetModel.PrimaryPart

                        local AlignOrientation = Instance.new("AlignOrientation")
                        AlignOrientation.Attachment0 = att0
                        AlignOrientation.Attachment1 = att1
                        AlignOrientation.RigidityEnabled = false
                        AlignOrientation.MaxTorque = PetModel.MaxForce.Value
                        AlignOrientation.Responsiveness = PetModel.Responsiveness.Value
                        AlignOrientation.Parent = PetModel.PrimaryPart
                        
                        game:GetService("RunService").Heartbeat:Connect(function()
                            att0.Position = PetModel.AttachmentPosition.Value
                            AlignPosition.MaxForce = PetModel.MaxForce.Value
                            AlignOrientation.MaxTorque = PetModel.MaxForce.Value
                            AlignPosition.Responsiveness = PetModel.Responsiveness
                        end)
                    end
                end
            end
        end 
    end

    function module.UnequipPet(Player)

    end

    function module.UnequipAllPet(Player)

    end

return module

end

,如果有人能帮我解决这个问题,那就太好了。

EN

回答 2

Stack Overflow用户

发布于 2022-07-27 20:56:03

一定要把“返回模块”放在最后!

票数 0
EN

Stack Overflow用户

发布于 2022-09-28 20:16:07

代码语言:javascript
复制
    return module

在功能范围内。试着在代码末尾放出来然后..。

我不确定,但我认为这是因为您正在模块内创建一个事件连接,我现在遇到了这个问题。我刚停止在模块中创建事件,问题就停止了。

尝试将其从de中删除。

代码语言:javascript
复制
game:GetService("RunService").Heartbeat:Connect(function()
     att0.Position = PetModel.AttachmentPosition.Value
     AlignPosition.MaxForce = PetModel.MaxForce.Value
     AlignOrientation.MaxTorque = PetModel.MaxForce.Value
     AlignPosition.Responsiveness = PetModel.Responsiveness
end)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72987103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档