I am making a soccer game and the issue I am having has to do with shooting. So the way it works is when the player shoots, if it goes into the goal, the ball is destroyed and a new one from server storage is cloned and placed in the center of the field for restart. What is annoying is it will work like 3 or 4 times in a row then all of the sudden there is an error that says attempt to index nil with waitforchild. This is the script for giving a player possession of the ball and the error always happens as soon as the new ball spawns in. The error is on line local possession1 = player:WaitForChild"Possession"
ball.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil and Possession.Value == false then
local char = hit.Parent
local Players = game:GetService("Players")
local player = Players:GetPlayerFromCharacter(char)
local possession1 = player:WaitForChild"Possession"
ball.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) ~= nil and Possession.Value == false then
local char = hit.Parent
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local possession1 = player:WaitForChild(“Possession”)
Yes the other variables have been defined and the issue with your script is that everything is in a server script and im pretty sure you cant call local player in a server script.
It can be touched by an NPC and since an NPC is not a player, it gives nil
ball.Touched:Connect(function(hit)
local char = hit.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(char)
if player and Possession.Value == false then
local possession1 = player:WaitForChild"Possession"