Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index local 'player' (a nil value)?

Asked by
Oficcer_F 207 Moderation Voter
5 years ago

Why doesn't this script work, I even checked if the thing that touches has a humanoid, and even with adding that - I get the same error I had. But why? Why do I even get an error without touching the flag? Here is the script:

script.Parent.Touched:Connect(function(hit) 

local  humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local  player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if player.Team.Name == "Wave" and humanoid.Parent:FindFirstChild("Invincibility") == false then
script.Parent.Parent = humanoid.Parent
local head = humanoid.Parent.Head
script.Parent.CFrame = head.CFrame * CFrame.new(0,2,0)
local weld = Instance.new("Weld")
weld.Part0 = head
weld.C0 = head.CFrame:inverse()
weld.Part1 = script.Parent
weld.C1 = script.Parent.CFrame:inverse()
weld.Parent = script.Parent
script.Parent.Anchored = false

end
end
end)


func =  script.Parent.RemoveWeld

    function func.OnInvoke()
        print(1)
    end

Why doesn't it work, and why do I get an error without touching the brick??

0
Try using print as the debug tool. MineBlow111 39 — 5y
0
"Nil Value" means the script doesn't knows what is the value. Meaning the script doesn't knows what the value "Player" is. I am not really good at scripting but try defining player in a different way, I guess. HeyItzDanniee 252 — 5y

1 answer

Log in to vote
1
Answered by
Wutras 294 Moderation Voter
5 years ago

Your problem is that you automatically assume that every humanoid has a player attached to it. That is wrong. You need to check if game.Players:GetPlayerFromCharacter(part.Parent) then local player =game.Players:GetPlayerFromCharacter(part.Parent) end Hope that helps. If it doesn't, I'll run some tests once I get home and take a closer look at it.

0
Hey, I found out about the issue before, but thanks for answering! No need to test out at home :) Oficcer_F 207 — 5y
Ad

Answer this question