Having an issue getting player position 2nd time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    This round ending and starting successfully on an admins chat
  2. What is the issue? Include screenshots / videos if possible!
    After I stop the event and start it again I get the error of:
attempt to index nil with 'Position'

the on chatted when they type “!EndEvent” it runs this

BindableEvent:Fire(false, 2)

and for start it runs

BindableEvent:Fire(true, 1)

Error is on

local target = FindNearest(rayOriginPart.Position)

Here is my main part of my code (server sided)

BindableEvent.Event:Connect(function(isRunning, id)
	print("called with", id)
	if running and isRunning then return end
	running = isRunning
	while running do
		local target = FindNearest(rayOriginPart.Position)
		if target then
			Target = target.HumanoidRootPart
		local origin = rayOriginPart.CFrame.Position
		local rayTarget = target_previous:Lerp(Target.Position, laser_TrackingAccuracy)
		local direction = (rayTarget - origin)
		local results = workspace:Raycast(origin, direction * 100, raycastParameters)
		if not results then
			results = {Position = rayTarget}
			if results.Instance.Parent:FindFirstChild("Humanoid") and not results.Instance:IsDescendantOf(workspace.HappyHome) and not results.Instance.Parent:IsA("Accessory") then
				if debounce == false then
					debounce = true
					local targetChar = results.Instance.Parent
					if targetChar then
						else debounce = false
					debounce = false
			elseif results.Instance:IsDescendantOf(workspace.HappyHome) then
				local NewDetector = Detector:Clone()
				NewDetector.Parent = workspace
				NewDetector.Position = results.Instance.Position

				local PartsList = NewDetector:GetTouchingParts()

				for _,Part in ipairs(PartsList) do
					if Part:IsDescendantOf(workspace.HappyHome.Home.House) then
						Part:ApplyImpulse(math.random(1, 100), math.random(100, 500), math.random(1,100))

		local distance = (results.Position - origin).Magnitude
		local LaserPosition = laserPart.Position
		LaserPart.Size = Vector3.new(laser_Thickness,laser_Thickness,distance)
		laserPart.CFrame = CFrame.new(origin, results.Position) * CFrame.new(0,0, -distance/2)

		target_previous = rayTarget

thanks in advanced.

Which line did the output say the error is on

Oh sorry I forgot that! There you go

Okay thanks! So what does rayOriginPart equal? Because I don’t see a variable for it.

Here is the few variables near it and the variable

local rayOriginPart = Eye
local laserPart = LaserPart
local raycastParameters = RaycastParams.new()

Okay, so now what does Eye equal?

The eye is an union part, that part is working, just the target after you end and start again doesn’t work

Is there any part in the code where it gets deleted/destroyed?

Nope, I was still alive even, sometimes it errors when I reset but when I started I was alive



above the line where the error occurs and tell me what it prints

Like I said, it can’t seem to find the player even if they are alive.
it errors when I try to print

attempt to index nil with 'Parent'