【发布时间】:2020-07-08 14:15:36
【问题描述】:
我正在尝试创建取件,但是当您取件时弹出错误消息。 这是错误:
Workspace.LogPickup.LogPickupScript:8: attempt to index nil with 'Parent'
脚本的第 8 行是变量 player。
代码如下:
local log = script.Parent
local logGuard = false
local function onTouch(partTouched)
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local playerStats = player:FindFirstChild("leaderstats")
local playerLogCount = playerStats:FindFirstChild("Has Log")
if humanoid and logGuard == false then
log.Transparency = 1
log.CanCollide = false
logGuard = true
playerLogCount.Value = 1
wait(5)
log.Transparency = 0
log.CanCollide = true
logGuard = false
end
end
log.Touched:Connect(onTouch)
【问题讨论】:
-
humanoid是nil。