I'm trying to create a dialogue script where if I was to position my mouse onto an npc and pressed a certain key it would begin the dialogue. However, after putting some conditions the getMouseTarget function ends up returning nil even though my mouse is on an npc. I'd be happy if someone could show me where I messed up. Any help would be appreciated
local target
function getMouseTarget()
local mousetarget = mouse.Target
if mousetarget and mousetarget:IsA("Model") and mousetarget:FindFirstChild("Humanoid") then -- Checks if the target is an actual humanoid compared to a normal model
if game:GetService("Players"):FindFirstChild(mousetarget.Name,true) then -- If the humanoid isn't an actual player
target = mousetarget
end
end
end
mouse.Move:connect(getMouseTarget)
print(target.Name)

5 comments
Line 5, "if mousetarget" doesn't describe anything.
What do you mean it doesn't describe anything?
you can't say "If mouse.target then" because mouse.target isn't being watched to see if it targets a specific thing to activate the If function.
You have to specify an if function for every dialougue NPC that you have
if is not a function.