ok so i have this npc, with a head that looks at you when u get close
and i’ve put a click detector in the head to make the npc chat
when clicking on the head it now pops up with double chats
and i’ve scanned the script multiple times with no problems
no errors popping up, and it wasnt doing this before
script:
local bodyPosition = script.Parent.BodyPosition
local bodyGyro = script.Parent.BodyGyro
local part = script.Parent
local minDist = 10
local message1 = false
local message2 = false
local message3 = false
local chatService = game:GetService("Chat")
bodyPosition.Position = script.Parent.Position
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if message1 == false then
chatService:Chat(part, "What do you seek young traveler?", "White")
message1 = true
else
wait()
if message2 == false then
chatService:Chat(part,"You wish to learn holy magic?","White")
message2 = true
else
wait()
if message3 == false then
if plr.leaderstats.Level.Value >= 50 then
if plr.secondaryData.Race.Value == "Vampire" then
chatService:Chat(part,"You are forbiddden from learning this magic", "Red")
message1 = false
message2 = false
message3 = false
return
else
chatService:Chat(part,"Very well then, I pass on my knowledge to you.","White")
print("in testing")
message1 = false
message2 = false
message3 = false
end
else
if plr.secondaryData.Race.Value == "Vampire" then
chatService:Chat(part,"You are forbiddden from learning this magic", "Red")
message1 = false
message2 = false
message3 = false
return
else
chatService:Chat(part,"Come back when you are level 50","White")
message1 = false
message2 = false
message3 = false
end
end
end
end
end
end)
while wait(.01) do
local players = game.Players:GetChildren()
for i = 1, #players do
local mainPart = workspace:WaitForChild(players[i].Name).HumanoidRootPart
local magnitude = (part.Position - mainPart.Position).magnitude
if magnitude <= minDist then
bodyGyro.CFrame = CFrame.new(part.Position,mainPart.Position)
break
end
end
end