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

Why does this part stay in the air and does not move?

Asked by 9 years ago

This is my script:

    local laser = Instance.new("Part", game.Workspace)
    laser.FormFactor = "Custom"
    laser.Size = Vector3.new(0.2, 0.2, 2.6)
    laser.CanCollide = false
    laser.Anchored = false
    laser.CFrame = CFrame.new(fireFromPart.Position, cPos)

    local prop = Instance.new("BodyVelocity")
    prop.Parent = laser
    prop.velocity = (cPos - handle.Position).Unit * velocity

I made a tool that shoots laser beam type things when you cleck the left button. Before I made this part of the script I just cloned the beam from serverstorage but that caused lag problems so I made it so it makes the beam inside the script. Now when I click the shoot button the beam shows up where it is supposed to show up, everything is right except the beam does not move. can anyone find a problem here?

If I change the part position or size when it's already shot it starts moving

0
Is it anchored? woodengop 1134 — 9y
0
It's obviously not anchored. Although not a real solution, you already have the bullet pointing in the correct direction. Now you can just use lookVector to make it fly straight. prop.velocity = laser.CFrame.lookVector * velocity Perci1 4988 — 9y
0
Is the beam sticking to your tool or any parts? I think it might be welding itself to something when it's parented to the workspace. aquathorn321 858 — 9y
0
There are no weld scripts in the tool or workspace. CodeSponge 125 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

It's either because where you place you laser instance or because you don't set velocity maxForce. TOOL is not defined here

local laser = Instance.new("Part", workspace);
local mouse = player:GetMouse();

laser.FormFactor = "Custom";
laser.Size = Vector3.new(2.6,2.6,2.6);
laser.TopSurface = "Smooth";
laser.BottomSurface = "Smooth";
laser.CanCollide = false;
laser.CFrame = TOOL.Handle.CFrame;
laser.CFrame = CFrame.new(laser.Position, mouse.Hit.p);

local laserVelocity = Instance.new("BodyVelocity", laser);
laserVelocity.velocity = laser.CFrame.lookVector * 90;
laserVelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge);
0
Fixed the problem by setting the CFrame before setting the size and other properties. Still thanks for the help! CodeSponge 125 — 9y
0
No problem! DewnOracle 115 — 9y
Ad

Answer this question