Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gun only firing at 0,0,0?

Hi! I made a gun and it only fires when I'm standing near 0,0,0.

player = game.Players.LocalPlayer
mouse = player:GetMouse()

function fire()
	local part = Instance.new("Part",player.Character)
	part.Size = Vector3.new(2,2,2)
	part.CFrame = CFrame.new(player.Character.Torso.CFrame.p,mouse.Hit.p)
	part.CanCollide = false
	part.Anchored = false
	local vel = Instance.new("BodyVelocity",part)
	vel.Velocity = part.CFrame.lookVector*100
	game.Debris:AddItem(part,3)
end

Whenever I use fire(), it'll only work if I am near 0,0,0. If I'm, say at 5,0,0, it won't work. The parts will just hang in the air.

2 answers

✓ Accepted answer

When you create new parts, they can get snapped to the Baseplate if they don't have smooth surfaces.

When you set their .CFrame, those snaps don't go away. Since they're attached to something anchored, they won't move.

When you're in the way, Instance.new probably pushes the part above the baseplate, so no snap can form.


Try either setting the .TopSurface and .BottomSurface of part to "Smooth", or using part:BreakJoints() after setting its .CFrame.

1 comment

0

That's new, thank you!

function fire()
local part = Instance.new("Part",player.Character)
part.Size = Vector3.new(2,2,2)
part.CFrame = CFrame.new(player.Character.Torso.CFrame.p,mouse.Hit.p)
part.CanCollide = false
part.Anchored = false
local vel = Instance.new("BodyVelocity",part)
vel.Velocity = part.CFrame.lookVector*100
part.Parent = nil
part.Parent = player.Character
game.Debris:AddItem(part,3)
end

This will reset the parts movement causing it to move. I have used this in scrips before. :3

This discussion is preserved as it was. New answers, comments, and votes are closed.