ServerScriptService.Script:13: attempt to index nil with 'Parent'

What is wrong with my script?

That’s line 13

function FindSkiers(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --Line 13
		return true
	end
end

ski.Touched:Connect(FindSkiers)
local isPlayerOnSki = FindSkiers()

If you want the whole script, then:

local goal = game.Workspace.goal
local ski = game.Workspace.ski
local skiPos = game.Workspace.skiPos
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(15, Enum.EasingStyle.Linear)
local goal = {CFrame = goal.CFrame}
local goal2 = {CFrame = skiPos.CFrame}
local Tween = tweenService:Create(ski, tweenInfo, goal)
local Tween2 = tweenService:Create(ski, tweenInfo, goal2)
local IsTweening = false

function FindSkiers(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		return true
	end
end

ski.Touched:Connect(FindSkiers)
local isPlayerOnSki = FindSkiers()


if isPlayerOnSki then
	if IsTweening == false then
		IsTweening = true
		Tween:Play()
		Tween.Completed:Connect(function()
			Tween2:Play()
			Tween2.Completed:Connect(function()
				IsTweening = false
			end)
		end)
	end
end

Thank you!

The problem is there is no argument in here. The original function had a “hit” parameter, but when you called this function it’s empty.

1 Like

The problem is here, you are trying to get a value in a variable which is called with built-in function. I’d script your thing like this:

local isPlayerOnSki = false

function FindSkiers(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
        isPlayerOnSki = true
	end
end

ski.Touched:Connect(FindSkiers)

Then if you’d like to change isPlayerOnSki variable back to false I’d use TouchEnded and turn in to false in the same way as I showed you above.

1 Like