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.
- 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.