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

My gun propells my players forward uncontrollably?

Hello!

So recently, I've been trying to make an FPS. Everything's going well, but I have one issue: My players get propelled at speeds (ranging from walking speed to flying through the sky) uncontrollably (until I come out of First Person).

I've made the arms un-collidable (if that's a word) as well as the gun. I'm using CFrames to move the arms, gun, etc.

I would add a video but my computer is being odd. Sorry.

Thanks for considering, MaximussDev.

EDIT: Main script.

repeat wait(1) until game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") and game.Workspace.CurrentCamera.CameraType ~= Enum.CameraType.Scriptable

local camera = game.Workspace.CurrentCamera
local viewModel = game.ReplicatedStorage.viewModel:Clone()
viewModel.Parent = camera
local weapon = game.ReplicatedStorage.Weapons[game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool").Name]:Clone()
weapon.Parent = viewModel

for _, piece in pairs(game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool"):GetChildren()) do
	if piece:IsA("Part") or piece:IsA("UnionOperation") then
		piece.Transparency = 1
	end
end

local joint = Instance.new("Motor6D");
joint.C0 = CFrame.new(1, -1.5, -2); -- what I found fit best
joint.Part0 = viewModel.Head;
joint.Part1 = weapon.Handle;
joint.Parent = viewModel.Head;

local function updateArm(key)
	local shoulder = viewModel[key .. "UpperArm"][key .. "Shoulder"]
	local cf = weapon[key].CFrame * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, 1.5, 0)
	shoulder.C1 = cf:inverse() * shoulder.Part0.CFrame * shoulder.C0
end

local function onUpdate(dt)
	viewModel.Head.CFrame = camera.CFrame
	updateArm("Right")
	updateArm("Left")
end

local aimCount = 0;
local offset = weapon.Handle.CFrame:inverse() * weapon.Aim.CFrame;

local function aimDownSights(aiming)
	local start = joint.C1;
	local goal = aiming and joint.C0 * offset or CFrame.new();
	
	aimCount = aimCount + 1;
	local current = aimCount;
	for t = 0, 101, 10 do
		if (current ~= aimCount) then break; end
		game:GetService("RunService").RenderStepped:Wait();
		joint.C1 = start:Lerp(goal, t/100);
	end
end

local function onInputBegan(input, process)
	if (process) then return; end
	if (input.UserInputType == Enum.UserInputType.MouseButton2) then
		aimDownSights(true);
	end
end

local function onInputEnded(input, process)
	if (process) then return; end
	if (input.UserInputType == Enum.UserInputType.MouseButton2) then
		aimDownSights(false);
	end
end

game:GetService("UserInputService").InputBegan:Connect(onInputBegan);
game:GetService("UserInputService").InputEnded:Connect(onInputEnded);

game:GetService("RunService").RenderStepped:Connect(onUpdate)

Used from a tutorial by @EgoMoose.

2 comments

0

Can you post the script that spawns/Adds force to the bullet?

0

Yup, for sure! Sorry about that. The only thing is, the bullets don't cause it, because it's only when it's in First Person. Here's the script (added to the main post) that gives the player the first person gun and arms, etc.

1 answer

✓ Accepted answer

Make every part in the tool massless. I hate that you can have can collide off and your player will still glitch with high part count tools. It's annoying but setting massless to true for each part will completely solve this bug.

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