Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm having troubles with StarterGear not assigning Tools?

Hey, I'm actually working on a shopGUI which has the {Player} purchase a new Tool then afterwards it removes the current Tool in their Backpack and StarterGear then replaces it with the new Tool, however, whenever the {Player} resets, the old Tool comes back!

		local magicTools = shopItems[purchasedItem][purchasedItem]:Clone()
		magicTools.Parent = player.Backpack
		
		local oldMagicTool = player.Backpack:FindFirstChildOfClass("Tool")
		oldMagicTool:Destroy() 
				
		local magicTools = shopItems[purchasedItem][purchasedItem]:Clone()
		magicTools.Parent = player.StarterGear
		
		local oldMagicTool = player.StarterGear:FindFirstChildOfClass("Tool")
		oldMagicTool:Destroy()

The code above has "magicTools" assign the new tool purchased (which works just fine) then deletes the "oldMagicTool" (which also works just fine..) but as I said earlier, whenever the {Player} resets, the "oldMagicTool" comes back and the "magicTools" is gone.

I actually have the "tempFire" (which is the "oldMagicTool") inside of StarterPack and "tempLightning" inside of ServerStorage if any of this is helpful!

I'd appreciate any support I can get. :)

2 answers

In your 8th line you're setting the parent to StarterGear, this makes it so that every time you respawn, you get that gear, try Backpack instead

local magicTools = shopItems[purchasedItem][purchasedItem]:Clone()
magicTools.Parent = player.Backpack

local oldMagicTool = player.Backpack:FindFirstChildOfClass("Tool")
oldMagicTool:Destroy() 

local magicTools = shopItems[purchasedItem][purchasedItem]:Clone()
local magicTools2 = shopItems[purchasedItem][purchasedItem]:Clone()
magicTools.Parent = player.StarterGear
magicTools.Parent = player.Backpack

local oldMagicTool = player.StarterGear:FindFirstChildOfClass("Tool")
oldMagicTool:Destroy()

1 comment

0

Thanks for the response speedyfox66, unfortunately testing out your code ended up giving me two of the "tempLightning" tools and also is spitting the error: "ServerScriptService.RemoteHandling:81: attempt to index local 'oldMagicTool' (a nil value)" and actually going onto Line 81 was "oldMagicTool:Destroy()", otherwise known as Line 13 in the comment you sent.

This discussion is preserved as it was. New answers, comments, and votes are closed.