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

Cloning tool from ReplicatedStorage to the player's backpack works in Studio but not in the game?

some psuedo code here to show you what i'm doing:

local weapon = game.ReplicatedStorage["GUN"]

function buy(GUI)
	
	if boughtWeapon then
		
		if player.Backpack:FindFirstChild("GUN") == nil then

			weapon:Clone().Parent = player.Backpack
			
		end
	end
	
end

Filtering enabled is off. Works perfectly in Studio but when I publish the game the tool is invisible and sends you flying if you equip it. Note that it still works perfectly fine even in the game if you just put it in StarterPack.

1 comment

0

Does the tool work fine in game (Not Studio) when it is not in the players backpack. It most likely has nothing to do with the Backpack but the tool itself not working in game.

2 answers

Turn on FilteringEnabled first, as it will protect your game from hackers and exploiters.

Also, "player" is not defined. Define it. Same for "boughtWeapon".

Altogether, this is what your script should look like:

--[[
Please note that locals will no longer work. Use standard variables.
It was alright 2 years ago, but they disabled it. You can only use locals within the same block of code now.
--]]
weapon = game.ReplicatedStorage("GUN")
boughtWeapon = true
part = script.Parent
player = game.Players:GetPlayerFromCharacter(part.Parent)
function buy()
	if boughtWeapon == true then
		if not player.Backpack:FindFirstChild(weapon) then
			weapon:Clone().Parent = player.Backpack
		end
	end
end
part.Touched:Connect(buy)

As for flinging the player upon equipping it, look in the script of the Tool. I can't help you with that, unfortunately.

2 comments

0

Yes I know that was just pseudo code not the real script. I'm still having the problem and I know that the problem isn't in the tool because it works fine if you just put it in the StarterPack. The problem only happens when you clone the tool.

0

Then I can't fix your problem.

Try this:

local weapon = game.ReplicatedStorage["GUN"]

function buy(GUI)
	if boughtWeapon then
	print('bought weapon!')

		if player.Backpack:FindFirstChild("GUN") == nil then
			local gunclone = weapon:Clone()
			gunclone.Parent = player.Backpack
		end
	end
end

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