首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试用“CameraMaxZoomDistance”索引零--我试着搜索解决方案,但没有找到一个

尝试用“CameraMaxZoomDistance”索引零--我试着搜索解决方案,但没有找到一个
EN

Stack Overflow用户
提问于 2021-06-13 06:35:30
回答 1查看 69关注 0票数 0

我试图使球员的最大变焦距离更多地取决于他们的力量(力量),因为力量越大,角色就越大。

但是我得到了上面的错误:

尝试用“CameraMaxZoomDistance”索引零

这是我的代码:

代码语言:javascript
复制
            hum:WaitForChild("BodyDepthScale").Value = .5 + (powr.Value / 250)
            hum:WaitForChild("BodyHeightScale").Value = .5 + (powr.Value / 250)
            hum:WaitForChild("BodyWidthScale").Value = .5 + (powr.Value / 250)
            hum:WaitForChild("HeadScale").Value = .5 + (powr.Value / 250)
            if powr.Value > 1000 then
                game:GetService("Players").LocalPlayer.CameraMaxZoomDistance = powr.Value / 50
            end
            if powr.Value > 200 then
                print('higher')
                hum.MaxHealth = powr.Value / 2
            end
EN

回答 1

Stack Overflow用户

发布于 2021-06-13 16:03:34

你的错误是说game:GetService("Players").LocalPlayer是零。根据LocalPlayer的文档:

此属性仅为LocalScripts (以及它们所需的ModuleScripts )定义,因为它们在客户端上运行。对于服务器(在其上运行脚本对象的代码),此属性为零。

您正在尝试访问特定字符模型的播放器对象,并且有几种不同的方法来获得它。您已经可以访问角色模型本身中的类人形对象,因此我建议使用玩家:GetPlayerFromCharacter函数来定位Player对象。

代码语言:javascript
复制
if powr.Value > 1000 then
    -- get the character model
    local character = hum.Parent

    -- lookup the player based on the character
    local PlayerService = game:GetService("Players")
    local player = PlayerService:GetPlayerFromCharacter(character)
    if not player then
        warn("Could not locate player from character : ", character.Name)
        return
    end

    -- adjust the player's camera zoom distance
    player.CameraMaxZoomDistance = powr.Value / 50
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67955554

复制
相关文章

相似问题

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