(in the vid I hover over the output but u cant see it so dw about it)
local Target = nil
local activounce = false
local Humanoid = script.Parent:WaitForChild("Humanoid")
local chasing = false
local Character = script.Parent
local Range = 45
local Debug = false
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local function Chase()
if Target ~= nil then
Humanoid:MoveTo(Target.Position)
else
return nil
end
end
local IsMoving = false
local function Move()
if IsMoving == false then
IsMoving = true
Humanoid:MoveTo(HumanoidRootPart.Position + Vector3.new(math.random(-25,25),0,math.random(-25,25)))
wait(math.random(1,3))
IsMoving = false
end
end
script.Parent.abouttagetreal.OnServerEvent:Connect(function(player)
if chasing == true then return end
print("connect")
local function ondeath()
player.CharacterRemoving:Connect(function()
chasing = false
end)
end
task.spawn(ondeath)
script.Parent.Head.ClickDetector.CursorIcon = "rbxassetid://1822114127"
script.p2enter:Play()
wait(0.2)
script.Parent.Head.ClickDetector.CursorIcon = "rbxassetid://"
script.chasesound:Play()
print('why hello')
chasing = true
while chasing do
print('hiyas')
if player and player.Character == nil then
chasing = false
script.chasesound:Stop()
else
print(""..player.Character.Name)
local Char = player.Character
if Char and Char:IsA("Model") then
if Char:FindFirstChild("HumanoidRootPart") then
local Root = Char:FindFirstChild("HumanoidRootPart")
if Char ~= Character then
if (HumanoidRootPart.Position - Root.Position).Magnitude <= Range then
if Target == nil then
Target = Root
else
repeat
wait(0.1)
if chasing ~= false then
Chase()
else
end
until (chasing == false)
print("omgyay")
script.chasesound:Stop()
-- do end stuff here
end
elseif (HumanoidRootPart.Position - Root.Position).Magnitude > Range and chasing == true then
Move()
end
end
end
end
wait()
end
wait()
Debug = false
end
end)
is my script. It is a server script that fires from a local script that fires every time perfectly. However, when I reset my character after activating the chase script once, the ai just doesn’t chase. I’ve tried breakpointing and finding the problem, but I just couldn’t find it. It even printed fine at the Chase function. The chase script was something I’d took off the toolbox, and then I just rescripted it to my needs, so I would say to look out for things or variables that just dont get changed and need to. The script has a load of if statements and despite me looking over all of them that just may be the problem? Im not quite sure. I don’t think this owuld be too hard to fix, its jsut that since I’m not on a high level of scripting yet, I can’t get ont he same pace with what other coders are trying to do sometimes; even if I do I can’t continue the script without forgetting somethign like a variable they were using in an if statement, making sure it’s left true for their if statement to be running (thats an example)
SOMETHING TO KEEP IN MIND! for some reason, in the output: the first time the event fires, the time it works, the prints print twice.. as if the script is running through itself two times from something like a return? in the second round I only see one print (this does indeed happen every time)
please help, all of it is greatly appreciated!