所以我在roblox工作室上制作了一个CameraScript,当玩家接触到一个机器人时,摄像机会聚焦到机器人上。但是for循环似乎不起作用。
Game.StarterPlayer.StarterPlayerScripts中的脚本:
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
local g = char.Name
print(g) --Just for debugging purposes
print("Player Loaded!")
tou(char)
end)
function tou(char)
print("Function had ran")
for _,p in pairs(char:GetChildren()) do
print("We're here loopin ur parts...")
p.Touched:Connect(function(hit)
print("Someone touched?")
if hit.Parent.Name == "Robot" and hit.Parent:IsA("Model") then
print("It's the robot!")
workspace.CurrentCamera.CFrame = hit.Parent.Look.CFrame
workspace.CurrentCamera.Focus = hit.Parent.Head.CFrame
print("Camlock should be successfull...")
else
print("That ain't a robot tho...")
end
end)
end
end这是一段无法工作的代码:
for _,p in pairs(char:GetChildren()) do
print("We're here loopin ur parts...")
p.Touched:Connect(function(hit)
print("Someone touched?")
if hit.Parent.Name == "Robot" and hit.Parent:IsA("Model") then
print("It's the robot!")
workspace.CurrentCamera.CFrame = hit.Parent.Look.CFrame
workspace.CurrentCamera.Focus = hit.Parent.Head.CFrame
print("Camlock should be successfull...")
else
print("That ain't a robot tho...")
end
end)
end我尝试将for循环直接放入CharacterAdded事件中,将print()放在调试中,但它只打印了以下内容:
17:55:24.242 <username> - Client - CamLockOnKill:5
17:55:24.243 Player Loaded! - Client - CamLockOnKill:6
17:55:24.243 Function had ran - Client - CamLockOnKill:12...but,它没有打印其他的。
发布于 2022-01-27 10:44:04
它不打印We're here loopin ur parts...,因此循环不运行。
不运行泛型for循环的唯一方法,如
for _,p in pairs(char:GetChildren()) do
end没有错误就是向pairs提供一个空表。
所以char没有孩子。找出为什么你认为它有孩子,为什么它没有。
https://stackoverflow.com/questions/70876851
复制相似问题