Heyy!!
I recently have stumbled upon this error in my game, and after looking it up I can see that there aren’t many ressources online, and mine doesn’t really match with the ones on here already.
So, after consulting some better developers (that also couldn’t fix it), I’ve decided to just post it here and hope for the best.
Essentially I keep getting this error (linked with this message, also in the title), there’s no line of code for where the error stems from, nor can i click on it. There’s also no blue/red lines in the script. However I know where the error comes from
I have this modulescript which manages a game mechanic (trick or treating), and I have a function MoveTo() which is supposed to move the npc using the arguments. It worked perfectly yesterday, but overnight it has decided to start giving me troubles. Here is the code:
local ChatService = game:GetService("Chat")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MechanicFolder = ReplicatedStorage:WaitForChild("MechanicFolder")
local SendToMechanicHandler = MechanicFolder:WaitForChild("SendToMechanicHandler")
local Data = game:GetService("ServerScriptService"):WaitForChild("Data")
local Manager = require(Data:WaitForChild("Manager"))
local MechanicSounds = workspace:WaitForChild("MechanicSounds")
local DoorRing = MechanicSounds:FindFirstChild("Ring")
local DoorOpen = MechanicSounds:FindFirstChild("DoorOpen")
local DoorClose = MechanicSounds:WaitForChild('DoorClose')
local Messages = {
FirstMessages = {
'Hey kid, what do you want?',
'Kid, scrub off will ya?',
'WHAT NOW?',
'I am so tired of seeing you guys, what do you want?',
'No, I dont want to buy anything.',
},
SecondMessages = {
'Candy, huh? Well...',
'Hmm, kid. You are stressing me. Hold up..',
'Let me think.'
},
ThirdMessages = {
'Here ya go bud.',
'Take this and get away!',
'Dont come back kid',
'You know what? How about..NO!'
},
}
function Messages.GetWalkPoint(RingPart)
local HousePart = RingPart.Parent.Parent
local Target = HousePart:WaitForChild('Target')
return Target
end
function Messages.ApplyCandy(player, n)
Manager.UpdateCandy(player, tonumber(n))
end
function Messages.MoveNPC(NPC, RingPart, PremadeTarget)
if NPC and RingPart then
local HousePart = RingPart.Parent.Parent
local TargetPart = HousePart:WaitForChild("Target")
if not PremadeTarget then
PremadeTarget = TargetPart
end
local Humanoid = NPC:FindFirstChild("Humanoid")
if not Humanoid then return end
local HousePart = RingPart.Parent.Parent
local TargetPart = HousePart:WaitForChild("Target")
print(NPC, Humanoid, TargetPart)
Humanoid:MoveTo(PremadeTarget.Position)
Humanoid.MoveToFinished:Wait()
end
end
function Messages.Success(Player, Humanoid, NPC, RingPart)
Messages.ApplyCandy(Player, math.random(7, 22))
Messages.MoveNPC(NPC, RingPart, nil)
task.wait(1)
task.spawn(function()
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
end)
end
function Messages.Failure(Player, Humanoid, NPC, RingPart)
Messages.MoveNPC(NPC, RingPart, nil)
task.wait(1)
task.spawn(function()
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
end)
end
function Messages.GenerateMessage(n)
if n == 1 then
return Messages.FirstMessages[math.random(1, #Messages.FirstMessages)]
elseif n == 2 then
return Messages.SecondMessages[math.random(1, #Messages.SecondMessages)]
elseif n == 3 then
return Messages.ThirdMessages[math.random(1, #Messages.ThirdMessages)]
end
end
function Messages.NewConversation(Player, NPC, Humanoid, RingPart)
local t = {}
for i = 1, 3 do
table.insert(t, i, Messages.GenerateMessage(i))
end
local Character = Player.Character or Player.CharacterAdded:Wait()
local Talk_Part = NPC:WaitForChild("Head")
local Talk_Part_Player = Character:WaitForChild("Head")
task.wait(1)
ChatService:Chat(Talk_Part, t[1], Enum.ChatColor.White)
task.wait(5)
ChatService:Chat(Talk_Part_Player, 'Trick or Treat!', Enum.ChatColor.White)
task.wait(5)
ChatService:Chat(Talk_Part, t[2], Enum.ChatColor.White)
task.wait(6)
ChatService:Chat(Talk_Part_Player, 'So? Whats it gonna be', Enum.ChatColor.White)
task.wait(5)
if t[3] == 'You know what? How about..NO!' then
ChatService:Chat(Talk_Part, t[3], Enum.ChatColor.Red)
Messages.Failure(Player, Humanoid, NPC, RingPart)
else
ChatService:Chat(Talk_Part, t[3], Enum.ChatColor.White)
Messages.Success(Player, Humanoid, NPC, RingPart)
end
end
function Messages.New(Player, NPC, RingPart)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
task.spawn(function()
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
task.wait(5)
SendToMechanicHandler:Fire(Player, RingPart.Parent:FindFirstChild("Door"))
local DoorOpen_Clone = DoorOpen:Clone()
DoorOpen_Clone.Parent = RingPart
DoorOpen_Clone:Play()
task.wait(DoorOpen_Clone.TimeLength)
DoorOpen_Clone:Destroy()
task.wait(20)
local DoorClose_Clone = DoorClose:Clone()
DoorClose_Clone.Parent = RingPart
DoorClose_Clone:Play()
task.wait(DoorClose_Clone.TimeLength)
DoorClose_Clone:Destroy()
end)
local DoorRing_Clone = DoorRing:Clone()
DoorRing_Clone.Parent = RingPart
DoorRing_Clone:Play()
local Teleporter = RingPart.Parent:WaitForChild("Teleporter")
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
task.spawn(function()
HRP.Position = Teleporter.Position
HRP.CFrame = CFrame.lookAt(HRP.Position, RingPart.Position)
end)
task.wait(1)
task.spawn(function()
local WalkPart = Messages.GetWalkPoint(RingPart)
NPC:WaitForChild("HumanoidRootPart").CFrame = WalkPart.CFrame
NPC.Parent = workspace
print(NPC)
task.wait(5)
Messages.MoveNPC(NPC, RingPart, WalkPart)
end)
task.wait(5)
Messages.NewConversation(Player, NPC, Humanoid, RingPart)
end
return Messages
Thank you!