Help with this error message please

Hello everyone, i have my game and this error, im not sure what it means or how to fix it, like the game/script works normally, but its annoying seeing this error message in the output. Any ideas on a solution?

Picture of the error:

this is the script (the second part of the script is to play a sound based on proximity of the killer to the survivor):

--** Does stuff for when the player is in danger

--// Services
local Players: Players = game:GetService("Players")
local Run: RunService = game:GetService("RunService")

--// Instances
local Player = Players.LocalPlayer

--// Fields
local Update = os.time()
local UpdateRate = 1 -- Chase update rate 
local ChaseRange = 60
local ChaseFade = false

--// Connections
Player.CharacterAdded:Connect(function(Character: Model)
	local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
	script.LowHealth:Stop()
	script.Chase:Stop()
	Humanoid.HealthChanged:Connect(function(health: number)
		if Player.IsCurse.Value == false then
			if health <= Humanoid.MaxHealth / 2 then
				Character.Animate.run.RunAnim.AnimationId = "rbxassetid://8750913972" -- Limping animation ID
				script.LowHealth:Play()
			else
				Character.Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"
				script.LowHealth:Stop()
			end
		end
	end)
	Humanoid.Died:Connect(function()
		script.LowHealth:Stop()
		script.Chase:Stop()
	end)
end)

Run:BindToRenderStep("Chase", Enum.RenderPriority.Last.Value, function()
	local Players: {Instance} = Players:GetPlayers()
	for i = 1, #Players do
		if Players[i]:FindFirstChild("IsCurse") and Players[i].IsCurse.Value and Players[i] ~= Player then
			local Curse = Players[i]
			if Curse.Character.PrimaryPart then
				if (Curse.Character.PrimaryPart.Position-Player.Character.PrimaryPart.Position).Magnitude <= ChaseRange and not script.Chase.Playing then
					ChaseFade = false
					script.Chase.Volume = 3
					script.Chase:Play()
				elseif (Curse.Character.PrimaryPart.Position-Player.Character.PrimaryPart.Position).Magnitude > ChaseRange and script.Chase.Playing then
					ChaseFade = true
					task.spawn(function()
						for i = 1, 0, -0.1 do task.wait(1 / 10)
							if not ChaseFade then break end
							script.Chase.Volume = i
						end
						script.Chase:Stop()
						ChaseFade = false
					end)
				end
			end
		end
	end
end)

Any help would be appreciated, me and my friend are stuck on this.

1 Like

Can you send me the line that is mentioned in the error?

Line 44 so if (Curse.Character.PrimaryPart.Pos) etc

Does PrimaryPart instance exist? Or does Curse have a character?

The RunService:BindToRenderStep() is run when your HumanoidRootPart hasn’t loaded yet. Try this:

--** Does stuff for when the player is in danger

--// Services
local Players: Players = game:GetService("Players")
local Run: RunService = game:GetService("RunService")

--// Instances
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hum_RT = Character:WaitForChild("HumanoidRootPart")

--// Fields
local Update = os.time()
local UpdateRate = 1 -- Chase update rate 
local ChaseRange = 60
local ChaseFade = false

--// Connections
Player.CharacterAdded:Connect(function(Character: Model)
	local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
	script.LowHealth:Stop()
	script.Chase:Stop()
	Humanoid.HealthChanged:Connect(function(health: number)
		if Player.IsCurse.Value == false then
			if health <= Humanoid.MaxHealth / 2 then
				Character.Animate.run.RunAnim.AnimationId = "rbxassetid://8750913972" -- Limping animation ID
				script.LowHealth:Play()
			else
				Character.Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"
				script.LowHealth:Stop()
			end
		end
	end)
	Humanoid.Died:Connect(function()
		script.LowHealth:Stop()
		script.Chase:Stop()
	end)
end)

Run:BindToRenderStep("Chase", Enum.RenderPriority.Last.Value, function()
	local Players: {Instance} = Players:GetPlayers()
	for i = 1, #Players do
		if Players[i]:FindFirstChild("IsCurse") and Players[i].IsCurse.Value and Players[i] ~= Player then
			local Curse = Players[i]
                        local char = Curse.Character or Curse.CharacterAdded:Wait()
                        local hum_rt = char:WaitForChild("HumanoidRootPart")
			if hum_rt  then
				if (hum_rt .Position-Hum_RT .Position).Magnitude <= ChaseRange and not script.Chase.Playing then
					ChaseFade = false
					script.Chase.Volume = 3
					script.Chase:Play()
				elseif (hum_rt .Position-Hum_RT .Position).Magnitude > ChaseRange and script.Chase.Playing then
					ChaseFade = true
					task.spawn(function()
						for i = 1, 0, -0.1 do task.wait(1 / 10)
							if not ChaseFade then break end
							script.Chase.Volume = i
						end
						script.Chase:Stop()
						ChaseFade = false
					end)
				end
			end
		end
	end
end)

Please note that I have not tested this code.

You can check if Player.Character ~= nil then or you can use the event as @FunAsiK did.

The primarypart is the humanoidrootpart of the monster/curse. And yes it has a character

when trying out your code, the error no longer shows in the output but the Chase music no longer plays when the monster is near. No error.