Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I'm having troubles with StarterGear not assigning Tools?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

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

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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()

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. ofek163 7 — 4y

Answer this question