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

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

Asked by 6 years ago
Edited 6 years ago

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.

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. LegitmateTrades 159 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

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. xXrawr_xdXxOwO 24 — 6y
0
Then I can't fix your problem. DeceptiveCaster 3761 — 6y
Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago

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

Answer this question