Please help with pick up script. It is inconsistent and sometimes does not work

  1. My pick up gem script often works. However, sometimes for some players it does not. It is inconsistent. I need suggestions on how to fix. I have 5 gems in the game, Blue, Pink, Yellow, Green, Purple. Each gem uses a copy of the same script (only the gem name is different). Many people complain they cannot get the Pink gem, but other gems will also sometimes not pick up, like yellow gem in the below YouTube example.

  2. Please see this YouTube video of 2 players playing the game. We Bought a MAGIC BALLOON! Roblox MAGIC BALLOON STORY - All Endings! ft SuperDog Tyler - YouTube
    Time: 17:10 - 17:25 both players are able to get the blue gem. Good!
    Time: 18:20 - 18:55 superdog_tyler can get the pink gem but snowi_fox cannot get the pink gem. Bad!
    Time: 19:35 - 19:50 snowi_fox tries to get the pink gem again, but it will not give it to her. Bad!
    Time: 20:30 superdog_tyler can get the green gem & Time: 22:10 snowi_fox can get the green gem. Good!
    Time: 22:40 superdog_tyler can get the purple gem & Time: 23:08 snowi_fox can get the purple gem + magic wand. Good!
    Time: 23:38 superdog_tyler can get the yellow gem & Time: 24:00 snowi_fox cannot get the yellow gem. Bad!

  3. It always works great for me. However, it is not always working for some players online. It seems so random. I am soooo lost how to troubleshoot this.

Players are reporting this gem pick up bug on my fan page. Mostly people complain specifically about the Pink gem. However, the Green gem has also been specifically mentioned. Also, we see in the above YouTube, the Yellow gem not working for snowi_fox, but being fine for superdog_tyler.

One of my players thinks they fixed the bug by changing their “metaverse clothing”. I have not confirmed this, but this is what they wrote: Hi pizzashark, I found a very interesting bug. It’s only the pink gem in the magic map part. It didnt give me the pink gem even if I touched it, because I was wearing metaverse clothing (wren’s pants and fey shirt). When I changed to other clothing, then only it gave me the pink gem. But I have no idea if this bug will exist with other metaverse pants and shirts or some combination of them. This is a secret bug LOL.

In the game there are also 3 Magic Wands and 5 Apples to pick up. No one has ever complained about these items. Therefore, I think people may not have trouble picking these up. The scripts to pick these items up are mostly similar to the gem pick up scripts.

-- This is code for picking up the the pink gem, the one people complain about most.

local trigger = script.Parent
local DB = false

---------------------------------------------------------
trigger.Sound.SoundId = "rbxassetid://3302699870"
pickUpItem = "Pink Gem"
---------------------------------------------------------

trigger.Touched:Connect(function(hit) -- when touch the parent

	if DB then return end -- In DeBounce?, no go!

	DB = true

	if hit == nil then return end -- no ?, no go!
	if hit.Parent == nil then return end -- no parent?, no go!

	local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player from hit
	if player ~= nil and player:FindFirstChild("Backpack") then -- are you a player with backpack?

		if player.Backpack:FindFirstChild(pickUpItem) or player.Character:FindFirstChild(pickUpItem) then -- Already have it.
			print("I already have the " .. pickUpItem)

		else

			local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
			item.Parent = player.Backpack -- Put tool in Players Backpack

			local humanoid = player.Character:FindFirstChildOfClass("Humanoid") --Make Player hold it in hand
			humanoid:EquipTool(item)

			local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
			item.Parent = player.StarterGear -- Put tool in Players Backpack

			trigger.Sound:Play()

			--trigger.Sound.Parent = game.Workspace  --keep acitve if this is a ONCE TIME PICK UP

			--trigger:Destroy()  --keep acitve if this is a ONCE TIME PICK UP

			trigger.Looker.Transparency = 1

		end


		wait(2)
		DB = false
		trigger.Looker.Transparency = 0.4
		trigger.PointLight.Brightness = 4

	end

end)
-- This is the script to pick up the purple gem, this one worked fine in the YouTube.  Notice it is identical to the problematic pink gem (except for gem name)

local trigger = script.Parent
local DB = false

---------------------------------------------------------
trigger.Sound.SoundId = "rbxassetid://3302699870"
pickUpItem = "Purple Gem"
---------------------------------------------------------

trigger.Touched:Connect(function(hit) -- when touch the parent

	if DB then return end -- In DeBounce?, no go!

	DB = true

	if hit == nil then return end -- no ?, no go!
	if hit.Parent == nil then return end -- no parent?, no go!

	local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player from hit
	if player ~= nil and player:FindFirstChild("Backpack") then -- are you a player with backpack?

		if player.Backpack:FindFirstChild(pickUpItem) or player.Character:FindFirstChild(pickUpItem) then -- Already have it.
			print("I already have the " .. pickUpItem)

		else

			local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
			item.Parent = player.Backpack -- Put tool in Players Backpack

			local humanoid = player.Character:FindFirstChildOfClass("Humanoid") --Make Player hold it in hand
			humanoid:EquipTool(item)

			local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
			item.Parent = player.StarterGear -- Put tool in Players Backpack

			trigger.Sound:Play()

			--trigger.Sound.Parent = game.Workspace  --keep acitve if this is a ONCE TIME PICK UP

			--trigger:Destroy()  --keep acitve if this is a ONCE TIME PICK UP

			trigger.Looker.Transparency = 1

		end


		wait(2)
		DB = false
		trigger.Looker.Transparency = 0.4
		trigger.PointLight.Brightness = 4

	end

end)
-- This is a script to pickup the apple, this one worked fine in the YouTube, and no one ever complains about the apples.

local trigger = script.Parent
local DB = false

---------------------------------------------------------
trigger.Sound.SoundId = "rbxassetid://3302699870"
pickUpItem = "Apple"
---------------------------------------------------------

trigger.Touched:Connect(function(hit) -- when touch the parent

	if DB == true then return end
	
	DB = true
	
	if hit == nil then return end -- no ?, no go!
	if hit.Parent == nil then return end -- no parent?, no go!
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player from hit
	if player ~= nil and player:FindFirstChild("Backpack") then -- are you a player with backpack?
		
		
		local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
		item.Parent = player.Backpack -- Put tool in Players Backpack

		local humanoid = player.Character:FindFirstChildOfClass("Humanoid") --Make Player hold it in hand
		humanoid:EquipTool(item)

		local item = game.ReplicatedStorage:FindFirstChild(pickUpItem):Clone() --Clone tool from Replacated Storage
		item.Parent = player.StarterGear -- Put tool in Players Backpack

		local PlayerName = player.Name -- Get and Send Name
		print("Player name is " .. PlayerName)
		game.ServerScriptService.PlayerApple.Value = player

		trigger.Sound:Play()

		trigger.Sound.Parent = game.Workspace  --keep acitve if this is a ONCE TIME PICK UP

		trigger:Destroy()  --keep acitve if this is a ONCE TIME PICK UP
	
	end
	DB = false
end)

I think that it might be fixed. Here’s how:
This is how you check if a part was touched by a player’s character:
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
Consider changing it to:
local player = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorOfClass("Model"))
I think that the clothing mentioned here makes player’s character have more parts parented to character’s children, not to the character. It don’t think that this will fix the issue completely (one way to find out).

Thank you so much for the reply!!!

I’m a new scripter, so sometimes I don’t even know where to start with troubleshooting.

I made the change. I’ve tested in studio, just me. Works great. However, now here is the big test… how it works in the wild! I’ve published the game with the update. I will now observe to see if a random player here or there somehow has trouble. That’s the weird thing about this bug… it seems so random. Hopefully that players hypothesis that her clothing was triggering the error was correct! I will give an update after I spend some time observing! Thank you again!!

So, I’ve made the fix, but I’m still getting complaints on my fan page. Does anyone have any more ideas on why the Pick Up is broken (only sometimes)?

I’d recommend trying to recreate the bugs. Or, you can join someone who’s experiencing the bug and take a look at the devconsole. I also noticed that in the pink and purple gem, you added a wait(2) before setting the debounce back to false. But, in the apple code, you didn’t add any wait(2), and it happened to be the one which didn’t have any issues.

Hi Encoded, thank you so much for the response. The gems can be taken again and again, so I had them temporarily disappear, once taken, with a wait(2) debounce. The apples are taken once then removed from the game, so I did not need a wait(2) debounce.

I will try removing the debounce on the gem, and not have it blink away for wait(2). If it could possibly solve the error, I’d gladly sacrifice the wait(2) disappear and reappear. I will try this and see.

But in general, does the code look generally good? I’m trying to find out if there is something basic I am overlooking or misusing in the code, as I am a beginner.

1 Like

Touched Events are generally inconsistent. I’d recommend adding a ClickDetector or a ProximityPrompt which the players can use to pick the gem/apple up. Another possible issue could be that you’ve named two variables the same.

So the tool is probably getting parented to the Backpack, and then the StarterGear.