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.
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.
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