变量返回为nil是什么原因?



giant_player一直返回nil,即使它从随机函数获得它的引用有什么问题吗?

local Players = game:GetService("Players")
local players = Players:GetPlayers()
wait(10)
for i = #players, 2, -1 do
local j = math.random(i)
players[i], players[j] = players[j], players[i]
end
local giant_player = players[1]
print(giant_player)
giant_player.TeamColor = BrickColor.new("Bright red")
giant_player.Character.Humanoid.WalkSpeed = 50
giant_player.Character.Humanoid.JumpPower = 100
giant_player.Character.HumanoidRootPart.Size = Vector3.new(6, 12, 6)
for _, player in ipairs(players) do
if player == giant_player then
player:Chat("You are the giant!")
else
player:Chat(giant_player.Name .. " is the giant!")
end
end
for _, player in pairs(players) do
if player == giant_player then
player.CameraMaxZoomDistance = 100
player.CameraMinZoomDistance = 10
player.CameraHeight = 20
player.Character.HumanoidRootPart.CanCollide = true
player.Character.HumanoidRootPart.Size = Vector3.new(6, 12, 6)
player.Character.HumanoidRootPart.CustomPhysicalProperties = PhysicalProperties.new(0.3, 0.3, 0.3, 1, 1)
player.Character.HumanoidRootPart:ClearAllChildren()
else
player.CameraMaxZoomDistance = 25
player.CameraMinZoomDistance = 5
player.CameraHeight = 5
end

脚本的目的是在玩家列表中随机找到一个玩家,并将其变成一个巨大的

你为什么要这样随机化呢?我就用数学。随范围随机。你可能会用for循环弄乱玩家表。我还没有测试过,但这应该从列表中为您随机选择一个球员。

local Players = game:GetService("Players")
local players = Players:GetPlayers()
wait(10)
local giant_player = players[math.random(1, #players)]
print(giant_player)

相关内容

  • 没有找到相关文章

最新更新