Gun pickup problem - Part 2

I decided to change pickup mechanic form Prompt to Raycasting so It could prevent people from picking weapons up on death

Everything was going alright at first


Until when I pick up then turn my camera away from the weapon, It does not catch up the weapon data properly, and not destroy the weapon as well

My pickup code (Client side):

function confirmWeapon(weapon) 
	if lastWeapon ~= weapon then
		lastWeapon = weapon
		if lastWeapon ~= nil then
			CAS:BindAction("PickupWeapon", function(actionName, inputState)
				if inputState == Enum.UserInputState.Begin then
					gunPickup(lastWeapon,
						lastWeapon:GetAttribute('CurrentAmmo'),
						lastWeapon:GetAttribute('AmmoStorage'),
						lastWeapon:GetAttribute('GunValue')
					)
					gunDestroy:FireServer(lastWeapon)
				end
			end, true, Enum.KeyCode.E)
		else
			CAS:UnbindAction("PickupWeapon")
		end
	end
end

Destroy weapon (Server side):

local RS = game:GetService('ReplicatedStorage')
local event = RS.Events:WaitForChild('GunDestroy')

event.OnServerEvent:Connect(function(player, weapon)
	weapon:Destroy()
end)

(Do not worry about defining variables, I did it properly in my game)

I tried to shoot ray after presseing E key, but nothing changed, but I cannot change back to ProximityPrompt cuz there is currently no way to disable the entire player’s keyboard (I tried from many posts and still failed)

1 Like

You can disable proximity prompt by just setting it’s Enabled state to false, alternatively with your pick up script you can just make it not execute the code if the player is dead

I really should have not made this post if I could find my own solution in just only a few minutes.
You can actually save the weapon data right when your mouse hovers on it, then send the data for use when the “E” key is confirmed. It would reduce errors while picking up weapon. L me.
Anyways, thanks for your suggestion, but I don’t think Prompt works the way I intended.