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

Why doesn't the tool goes to the backpack?

So i created a tool system where u click the button to buy a tool but it doesn't put the tool on players backpack it only puts it on starter gear

here is the script check it.

local player = game.Players.LocalPlayer
local Coins = player.leaderstats.Coins
local Tool = game.ReplicatedStorage.ClassicSword
script.Parent.MouseButton1Click:Connect(function(player)
	if Coins.Value >= 1000 then
		Coins.Value = Coins.Value - 1000
		local CloneTool = Tool:Clone()
		Tool.Parent = player.Backpack
		Tool.Parent = player.StarterGear
		
	end
end)

3 comments

0

why u wanna put it inside starter gear

0

^ So they can respawn with it.

0

yes

1 answer

✓ Accepted answer

first thing first, your mistake is you define 2 player by local player and parameter local player = game.Players.LocalPlayer and script.Parent.MouseButton1Click:Connect(function(player)

second is you put the tool from replicated storage into player backpack you should do this

 local CloneTool = Tool:Clone()
Tool.Parent = player.Backpack -- Wrong, This mean you make the tool parent to backpack
CloneTool.Parent = player.Backpack --Right, This mean you make the clone parent to backpack

and third you cant parenting a tool twice

this is the right code

local plr = game.Players.LocalPlayer
local Coins = plr.leaderstats.Coins
local Tools = game.ReplicatedStorage.ClassicSword
script.Parent.MouseButton1Click:Connect(function()
	if Coins.Value >= 1000 then
		Coins.Value = Coins.Value - 1000
		local Tool = Tools:Clone()
		Tool.Parent = plr.Backpack
		local Tool2 = Tools:Clone()
		Tool2.Parent = plr.StarterGear
	end
end)

make this as a correct answer, Thank you

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