Need a lot of help

I’m trying to make an inventory system that allows for two items to be picked up and dropped

Items get picked up in the left hand first and then the right hand
Items get dropped in the right hand first and then the left hand

I probably did it really wrong because I am running into a bunch of problems
Picking up the items works fine, but dropping them is where the issues show up.

  1. When it’s supposed to drop the item, it doesn’t drop it and the item usually stays in place.

  2. Sometimes I get this error and other times I don’t

I’m going to link an uncopylocked version of the game so that hopefully at least 1 person can play around with it and help me. I will restart it all if necessary

1 Like

Hey,

I’m kind of learning a bit with you, and I’ve also been stuck on this too. For dropping, you wrote

“player.Character:FindFirstChild(InventorySlots.right)”

on line 35. I think that may be one of the problems because it gives the “ServerScriptService.Script.InventoryModule:36: attempt to index nil with ‘Parent’” error. This is because the grabbed items are in the local camera, not the character.

to fix this, I just added 2 more variables in the “InventorySlots” module (leftitem and rightitem):

hands = {
left = nil,
leftitem = nil,
right = nil,
rightitem = nil
}

these are going to be the exact location of the grabbed items.

After this, I added:

InventorySlots.leftitem = item

and

InventorySlots.rightitem = item

under line 14 and 20 of inventory module so you can tell the drop function what to drop.

After that, I did was turn your original variable on line 37 and 43 from

local item = player.Character:FindFirstChild(InventorySlots.right) (or left)

to:

local item = InventorySlots.rightitem (or leftitem)

The last thing I did was make leftitem and rightitem nil after lines 41 and 47

InventorySlots.left = nil (or right)
InventorySlots.leftitem = nil (or rightitem)

One last thing was on VHS script (line 19), just incase make sure to change workspace.Baseplate to workspace:WaitForChild(“Baseplate”). This is necesary because if it takes a bit for a client to load the game (like me), the script will look for baseplate before it’s even loaded.

If you do all this you should (hopefully) atleast be able to drop things. I’m unfortunatly not sure why gravity isn’t working or anything else (I’m so sorry), but I hope this at least helped a bit. I’m sorry.

1 Like

This actually helped me a lot, thank you!

Using some of the changes you came up with combined with some new solutions I came up with, I got to a point where it sort of works, but the only problem is that the renderstepped function for the right hand isn’t disconnecting, which leads any item in the right hand to still appear on the client even after it has been dropped.

If you still want to help, ill link the game again here. I can’t figure out why the runservice function for the right hand isn’t disconnecting but the one for the left hand IS disconnecting, because they’re the same exact thing.

1 Like

Good news! I figured out a way to correctly disable both functions so the items both drop! Sort of…

Before I tell you what I did to (sort of) resolve the problem, I just have to let you know something.

The first thing I tried doing was try to make some print statements in a few places. the 1st place I put them was line 49 of the local script. And I just found out that the 2nd time you grab an item (Not only grabbing a left, then right item, also grabbing a left, dropping then getting another left) it will run run service twice)

image

This is the most likely reason why the item is not dropping in the right hand every time.

Now for what I personally did to sort of fix the problem. (Only local script)

I added two new variables at the start of the local script

local Lhold = false
and
local Rhold = false

With these, I can check if the player wants to pickup or drop an item. I just add an “if Lhold (or Rhold) then” at the start of each RS. at the end of the RS code, and added an else, which just means if Lhold/Rhold (player isn’t holding anything) it runs this code

else
item:Destroy() – So it get’s droped
print(“destroyedL”) – to check if it ran (and also to talk about something later)

Quick note: I don’t know if I mentioned this last time I posted, but the leftHandRS and rightHandRS were not defined in the code at all. I think just in case you should add this at the start of the code.

local leftHandRS
local rightHandRS

Just so you don’t get an error later.

After that, after line 100 and 102, add this

Lhold = false (or Rhold)

I think this should make it work now.

The only thing I think you should be aware of is the 2nd grabbed item still running Runservice

image (It will keep running)

Other than adding another an interactable tag to all other items (only pumpkin and fries have them), and on the local script change the Enum.RaycastFilterType on line 21 from Blacklist to Exclude (I think blacklist is depricated, that should hopefully be it!

Have a happy new year!!!

1 Like

This is the new local script:

local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")
local cs = game:GetService("CollectionService")
local uis = game:GetService("UserInputService")
local rstorage = game:GetService("ReplicatedStorage")

local tween = ts:Create(script.Parent, TweenInfo.new(.06, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true), {Position = UDim2.new(0, 0, -0.5, 0)})
tween:Play()

local camera = game.workspace.CurrentCamera

local rightHandOffset = CFrame.new(2,-1,-2)
local leftHandOffset = CFrame.new(-2,-1,-2)

local leftHandRS
local rightHandRS



rs.RenderStepped:Connect(function()
	game.Players.LocalPlayer:GetMouse().Icon = "http://www.roblox.com/asset/?id=93431704962808"
	
	local rayParams = RaycastParams.new()
	rayParams.FilterDescendantsInstances = {workspace:WaitForChild("Baseplate"), game.Players.LocalPlayer.Character}
	rayParams.FilterType = Enum.RaycastFilterType.Exclude
	result = game.Workspace:Raycast(camera.CFrame.Position, camera.CFrame.LookVector * 100, rayParams)
	
	if result then
		if cs:HasTag(result.Instance, "Interactable") then
			game.Players.LocalPlayer:GetMouse().Icon = 'http://www.roblox.com/asset/?id=139920085805654'
		else
			game.Players.LocalPlayer:GetMouse().Icon = 'http://www.roblox.com/asset/?id=93431704962808'
		end
	end
	
end)



-------------------------------------------------------------------------------------------------------------



uis.InputBegan:Connect(function(input, gpe)
	if gpe then return end
	
	if result and input.KeyCode == Enum.KeyCode.E and cs:HasTag(result.Instance, "Interactable") then
		
		rstorage.ItemPickup:FireServer(result.Instance)
		
	elseif input.KeyCode == Enum.KeyCode.Q then
		
		rstorage.ItemDrop:FireServer()
		
	end
end)


rstorage.ItemPickup.OnClientEvent:Connect(function(item, availableHand)
	if availableHand == "left" then

		leftHandRS = rs.RenderStepped:Connect(function()
			if camera:FindFirstChild(item.Name) then camera:FindFirstChild(item.Name):Destroy() end
			local toolviewmodel = item:Clone()
			toolviewmodel.Parent = camera
			toolviewmodel.CFrame = camera.CFrame * leftHandOffset
			print("left rs")
		end)

	elseif availableHand == "right" then

		rightHandRS = rs.RenderStepped:Connect(function()
			if camera:FindFirstChild(item.Name) then camera:FindFirstChild(item.Name):Destroy() end
			local toolviewmodel = item:Clone()
			toolviewmodel.Parent = camera
			toolviewmodel.CFrame = camera.CFrame * rightHandOffset
			print("right rs")
		end)

	end
end)


rstorage.ItemDrop.OnClientEvent:Connect(function(handToDropFrom, itemName)
	print("handToDropFrom = ", handToDropFrom)
	print("itemName = ", itemName)
	camera:WaitForChild(itemName):Destroy()
	if handToDropFrom == "right" then
		rightHandRS:Disconnect()
	elseif handToDropFrom == "left" then
		leftHandRS:Disconnect()
	else
		warn("Client Drop Error")
	end
end)

This ended up working! I had to switch a few things around and also changed some minor issues. Thank you and happy new year!

1 Like

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