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

Why won't the bodypositon within the coroutine move object to mouse.hit.p?

Asked by 9 years ago
repeat wait() until (game.Players.LocalPlayer ~= nil) and (game.Players.LocalPlayer.Character ~= nil); 
Client_Pl = game.Players.LocalPlayer;
Client_Char = Client_Pl.Character;
Mouse = Client_Pl:GetMouse();

Client_Cam = game.Workspace.CurrentCamera; 

Resources = game.Lighting.Resources;
Tools = Resources.Tools;
Enviroment = workspace.Enviroment; 

Mode_Deb = false;
Mode = "Happy";

WallDetail = {};
FloorDetail = {};

CamTrackP = Instance.new("Part",Client_Char);
CamTrackP.Transparency = 1; 
CamTrackP.CanCollide = false; 
CamTrackP.Name = "CamTrackP"; 

ContainObject = false;
CurrentObject = nil;

GetAttire = Client_Char:GetChildren(); 
for i = 1, #GetAttire do
if (GetAttire[i].ClassName == "Hat") or (GetAttire[i].ClassName == "Shirt") or (GetAttire[i].ClassName == "Pants")  then
GetAttire[i]:Destroy();
end
end

-- Coroutines
local ObjToMouse = coroutine.create(function(BodyPos)
while (ContainObject == true) do 
if (Mouse.Target ~= CurrentObject) and (Client_Char.Torso.Position - Mouse.Hit.p).magnitude <=26 then
BodyPos.position = Mouse.Hit.p;
end
wait(0.01)
end
end)

local MaxCircP = coroutine.create(function(MaxC)
while true do 
MaxC.position = Client_Char.Torso.Position+Vector3.new(0,-2.8,0);
wait(0.01)
end
end)
-- Coroutines

MaxCirc = Instance.new("Part",Client_Cam);
MaxCirc.Name = Client_Pl.Name.."MaxCirc"; 
MaxCirc.TopSurface = "Smooth"; 
MaxCirc.BottomSurface = "Smooth";
MaxCirc.FormFactor = "Custom";
MaxCirc.CanCollide = false;
MaxCirc.Transparency = 1;
MaxCirc.Size = Vector3.new(32,0.5,32);
MaxCirc.BrickColor = BrickColor.new("Dark green");

CylMesh = Instance.new("CylinderMesh",MaxCirc);
CylMesh.Name = "CylMesh";

MCBodyPos  = Instance.new("BodyPosition", MaxCirc);
MCBodyPos.Name = "COBodyPos"; 
MCBodyPos.maxForce = Vector3.new(1000000,1000000,1000000);

coroutine.resume(MaxCircP,MCBodyPos);

Mouse.Button1Down:connect(function()
if (Mouse.Target ~= nil) and (ContainObject == false) and (Client_Char.Torso.Position - Mouse.Hit.p).magnitude <= 10 then
GetMOV = Mouse.Target:FindFirstChild("Moveable");
GetTOU = Mouse.Target:FindFirstChild("Touchable");
if (GetTOU ~= nil) and (GetMOV.Value == true) and (GetTOU.Value == true) then
MaxCirc.Transparency = 0.6
GetTOU.Value = false;  
CurrentObject = Mouse.Target;
ContainObject = true;
COBodyPos = Instance.new("BodyPosition", Mouse.Target);
COBodyPos.Name = "COBodyPos"; 
COBodyPos.maxForce = Vector3.new(100000,100000,100000);
COBodyAV =  Instance.new("BodyAngularVelocity", Mouse.Target);
COBodyAV.Name = "COBodyAV";
COBodyAV.maxTorque = Vector3.new(10000,10000,10000);
COBodyAV.angularvelocity = Vector3.new(0,10,0);
coroutine.resume(ObjToMouse,COBodyPos);
wait(1)
end
else if (ContainObject == true)then
coroutine.yield(ObjToMouse);
MaxCirc.Transparency = 1;
CurrentObject.COBodyPos:Destroy();
CurrentObject.COBodyAV:Destroy();
GetTOU.Value = true;  
CurrentObject = nil;
ContainObject = false;
end
end

end)


Answer this question