i'm making a script in which if you press the key "C" then it makes a clone of your character and the clone attacks near by npcs but my script isn't working. I tried to use pcall function but it still doesn't work. Any help?
Here is my script.
game.ReplicatedStorage.Events.CloneEvent.OnServerEvent:Connect(function(plr)
plr.Character.Archivable = true
wait()
local clone = plr.Character:Clone()
clone.Parent = workspace
clone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
clone.HumanoidRootPart.CFrame = plr.Character.UpperTorso.CFrame + Vector3.new(0,0,5)
local player = game.Players:GetPlayerFromCharacter(plr.Character)
local NPC = workspace:FindFirstChildWhichIsA("Model")
if NPC and NPC ~= player then
local animation = Instance.new("Animation",clone)
animation.AnimationId = "http://www.roblox.com/asset/?id=742640026"
local play = clone.Humanoid:LoadAnimation(animation)
play:Play()
pcall(function()
local path = game:GetService("PathfindingService"):CreatePath()
local goal = NPC.HumanoidRootPart.Position
path:ComputeAsync(clone.HumanoidRootPart.Position,goal)
local points = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for _, point in pairs(points) do
if point.Action == Enum.PathWaypointAction.Jump then
clone.Humanoid.Jump = true
while true do
wait()
clone.Humanoid:MoveTo(point.Position)
end
end
end
end
end)
end
end)

2 comments
What are you trying to use pcall() for? It's only for catching errors and containing them so your scripts don't fully break, and if you used pcall() you would of gotten an error beforehand. Please provide us with errors since I can't really do anything.
There are no errors