Roblox Lua丧尸波次脚本报错:attempted to index nil with humanoid求助
问题解决:Roblox丧尸脚本报错'attempted to index nil with humanoid'
错误根源
- 克隆丧尸后未设置父对象就直接调用
Parent属性,此时zombieCopy.Parent为nil,自然无法索引HumanoidRootPart - 存在拼写错误:
spwn.Postiion应为spwn.Position
修正后的脚本
local spawns = script.Parent local spawn_time = 10 while true do wait(spawn_time) for _, spwn in pairs(spawns:GetChildren()) do if spwn:IsA('BasePart') then local zombieCopy = game.ReplicatedStorage['Drooling Zombie']:Clone() -- 先把克隆体挂载到工作区,才能访问内部部件 zombieCopy.Parent = workspace -- 修正Position拼写错误 zombieCopy.HumanoidRootPart.CFrame = CFrame.new(spwn.Position + Vector3.new(0,3,0)) end end end
补充说明
- 克隆对象后必须先指定
Parent(比如workspace),否则克隆体处于未挂载状态,无法正常访问其内部子对象 - 编写脚本时注意检查变量名拼写,这类低级错误很容易引发难以排查的报错
内容的提问来源于stack exchange,提问作者Smulsqueen Gaming
相关产品推荐
相关产品推荐

