Hello everyone,
I have stumbled upon this issue while making an NPC move to the mouse’s position.
script:
MovmentEvent.OnServerEvent:Connect(function(player,model,MovementPosition)
print("Signal Received")
if model:GetAttribute("Owner") == player.Name then
model.Humanoid:MoveTo(MovementPosition)
model.Humanoid.MoveToFinished:Connect(function(reached)
print((model.HumanoidRootPart.Position - workspace.yznyzndx.Dummy.HumanoidRootPart.Position).Magnitude)
if reached and (model.HumanoidRootPart.Position - workspace.yznyzndx.Dummy.HumanoidRootPart.Position).Magnitude <= 10 then
print("Near")
end
end)
end
end)
local script:
Mouse.Button1Up:Connect(function()
print(1)
local Target = Mouse.Target.Parent
------------------ Variable used to tell the script what the mouse touched
if Target:IsA("Model") and Target:GetAttribute("Owner") == player.Name and Target:GetAttribute("Selected") == false then
------------------ Check if the target is a unit and owned by the player
print("Worked")
Target:SetAttribute("Selected",true)
local SelectionBoxClone = SelectionBox:Clone()
SelectionBoxClone.Color3 = Color3.fromRGB(255, 0, 0)
SelectionBoxClone.Parent = Target
SelectionBoxClone.Adornee = Target
------------------ These lines gives the unit a speical trait so the player knows it has been selected
else
------------------ if the player didn't press on a unit this will activate instead
for i,v in ipairs(PlayerFolder:GetChildren()) do
print(2)
if v:IsA("Model") and v:GetAttribute("Selected") == true then
MovementEvent:FireServer(v,Mouse.Hit.Position)
end
end
------------------ This will check if the player have selected any units and move them to the mouse's position
end
end)
The problem is that the more I move the NPC the more the print on the server script will fire.
Here is an example:
as you can see the line 17 of the script keep printing the more I move the NPC.
any help would be great.
Thank you