When I pick up an item and then jump, my character launches. Using FPSTemplate

I have a game where I have a weapon on the floor. After I wait about 3 minutes, when I go to pick up that weapon, my character launches super far. I have a grab script, and a throw weapon script. This never happens when I first start up the game, and there doesnt seem to be anything that “triggers” it, if I launch the game, literally dont touch my keyboard at all, and then pick up the weapon and jump, the bug will occur. The bug does not seem to occur when I wait a few seconds to jump after picking up the weapon.

This is the Grab script:

local RS = game:GetService("ReplicatedStorage")
local weaponFolder = RS.WeaponTools

--to use this script make sure every weapon in the replicatedStorage/weapontools folder has the Weapon tag
--each tool in the folder must also have a proximity prompt inside the model

--allows for picking up weapon off the floor

--bug to fix is that after weapon is thrown cant re pick up weapon might be something in this script or weaponthrow script

local function setupWeaponPickup(weapon)
	local model = weapon:FindFirstChildWhichIsA("Model")
		if model then
			local prompt = model:FindFirstChild("ProximityPrompt") :: ProximityPrompt
			if prompt then
				local conn
				conn = prompt.Triggered:Connect(function(playerWhoTriggered)
					prompt.Enabled = false
					local humanoid = playerWhoTriggered.Character:FindFirstChildOfClass("Humanoid")
					local weaponClone = weaponFolder:FindFirstChild(weapon.Name):Clone()
					weaponClone.Parent = playerWhoTriggered.Backpack
					humanoid:EquipTool(weaponClone)
					weapon:Destroy()
					conn:Disconnect()
				end)
			end
		end
end

for i, weapon in pairs(CollectionService:GetTagged("Weapon")) do
	setupWeaponPickup(weapon)
end

CollectionService:GetInstanceAddedSignal("Weapon"):Connect(function(weapon)
	if weapon:IsA("Tool") then
		setupWeaponPickup(weapon)
	end
end) 

This is the weapon throw script, though I don’t think this is the culprit, as this issue occurs despite a weapon not having been thrown yet:

local RS = game:GetService("ReplicatedStorage")
local weaponFolder = RS.WeaponTools
local event = RS.Throw

local PICKUP_COOLDOWN = 0

event.OnServerEvent:Connect(function(player: Player, tool: Tool) 
	print("player is " .. player.Name)
	print("tool is " .. tool.Name)
	
	local character = player.Character
	if not character then
		warn("Character not found for player " .. player.Name)
		return
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		warn("Humanoid not found for player " .. player.Name)
		return
	end

	local head = character:FindFirstChild("Head")
	if not head then
		warn("Head not found for player " .. player.Name)
		return
	end

	
	local lookDirection = head.CFrame.LookVector
	local throwPosition = head.Position + lookDirection * 3 + Vector3.new(0, 0.5, 0)

	--make a folder with all weapons and get the tool.name and find the same tool in the folder and clone that one instead. 
	--local toolCopy = weaponFolder:FindFirstChild(tool.Name):Clone()
	local toolCopy = tool:Clone()
	--toolCopy:SetAttribute("_ammo", )

	local toolHandle = toolCopy:FindFirstChild("Handle") :: Part
	local model = toolCopy:FindFirstChildWhichIsA("Model")
	local handle = model:FindFirstChild("Handle")
	if handle then
		print("has handle")
		handle.Anchored = false
		handle.CanCollide = false
		toolHandle.CanCollide = true
		
		local prompt = model:FindFirstChild("ProximityPrompt")
		prompt.Enabled = false
		
		
		
		toolCopy.Parent = workspace
		toolHandle.Position = character.HumanoidRootPart.Position
		handle.CFrame = CFrame.new(throwPosition)
		
		
		
		
		for _, part in pairs(model:GetDescendants()) do
			if part:IsA("BasePart") then
				part.AssemblyLinearVelocity = lookDirection * 35
				--part.Transparency = 1
			end
		end


		task.delay(PICKUP_COOLDOWN, function()
						if prompt and prompt.Parent then
							prompt.Enabled = true
						end
					end)
	end
	
	tool:Destroy()
	print("thrown")
end)

Video demonstrating the bug, sorry for the quality, I had to low it to 480p to meet the 10mb limit.

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub? I’ve tried setting velocity to 0, like this:
for _, descendant in ipairs(weaponClone:GetDescendants()) do
   	if descendant:IsA("BasePart") then
   		descendant.AssemblyLinearVelocity = Vector3.zero
   		descendant.AssemblyAngularVelocity = Vector3.zero
   	end
   end. 

I’ve a bunch of other things, but it’s difficult to remember them all, however most of them boiled down to making sure there was no velocity on the object when picking it up.

1 Like

also ignore this comment, forgot to remove it and its no longer accurate.

I’m pretty sure you can fix this by making all the parts in the gun massless.
Here’s a test I did with a large part welded to my character, with mass vs massless:

edit: massless is more stable which is why I thought it → MIGHT ← be a solution

We’ve tried making the viewmodel and the object on the ground massless, both did not fix the issue. In the video example I posted, the object on the ground is massless, however the viewmodel wasn’t, so I went to double check if making the viewmodel massless fixed it and it did not.

1 Like

I just realized the gun is constantly moving towards the camera’s lookvector. It might be that on the client the gun can move up and down but on the server it can only move horizontally and there’s also a delay from ping, causing some inconsistencies and flinging the character around. It’s the middle of the night right now but try experimenting with that.

We tried messing around with this and didn’t get anywhere. I dont think this is the solution, it doesnt really explain the behavior of the issue only occuring after the server has been open for 2 or 3 minutes. Our initial assumption was that there was some weird non determinism with how the object gets cleaned up when you pick it up, but once we found out that this only happens after the servers been open for a few minutes, we figured thats probably not the case. We’ve also ended up trying just about every suggestion every ai you can think of gives (we were desperate lol), and nothing fixed the issue.

Found the solution. When picking up the weapon, the whole model was getting cloned as well, and all the parts of the model were getting set to cancollide.

for _, descendant in ipairs(weaponClone:GetDescendants()) do
						if descendant:IsA("BasePart") then
							descendant.CanCollide = false
							descendant.CanTouch = false
						end
					end

We added this to the grab script and it fixed it. For some reason after this loop completes all the parts appear to dissappear from the file structure of the viewmodel (if anyone knows why that is, please respond, it doesn’t seem to affect functionality but I am curious as to why disabling collision on all the parts deletes them).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.