Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

having issues getting two if statements getting a single while loop to function?

Asked by
Hizar7 102
5 years ago

here is my issue I am trying to get two guys to do whats in the while loop. which is to follow the player and to return to their spawn, but i cant seem to get this right.. I just made this script in this for an example.. Please help!

local h = game.Workspace.guy1.Humanoid
local b = game.Workspace.guy2.Humanoid
local UpperTorso = game.Workspaceguy1.UpperTorso
local UpperTorsoA = game.Workspace.guy2.UpperTorso
local spawnCF = UpperTorso.CFrame
local spawnCFA = UpperTorsoA.CFrame

function findPlayer()
 for _,v in next, game.Players:GetPlayers() do
  if v.Character then
   local char = v.Character
   if char:FindFirstChild("Humanoid") and char:FindFirstChild("UpperTorso") then
    local pUpperTorso = char.UpperTorso
    if (pUpperTorso.Position - UpperTorso.Position).magnitude <= 30 then
    else h = nil 
 if (pUpperTorso.Position - UpperTorsoA.Position).magnitude <= 30 then
    else b = nil 
     return v
    end
   end
end
  end
 end
 return nil
end
while wait() do
 local player = findPlayer()
 if player ~= nil then 
if h ~= nil then 
  h.WalkToPoint = player.Character.UpperTorso.Position
else
    if b ~= nil then  
 b.WalkToPoint = player.Character.UpperTorso.Position
 else
 h.WalkToPoint = spawnCF.p
 b.WalkToPoint = spawnCFA.p
    end
end
end
end
0
indentation 10/10 aazkao 787 — 5y
0
I think the funky indentation is roblox's fault this time User#21908 42 — 5y
0
You have to put something in an if statement, you can't write "then else" User#22604 1 — 5y
0
If you only want something to run if a condition is NOT true, you can write "if not (yourconditional) then" User#22604 1 — 5y

Answer this question