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

Swapping Tools Script?

Asked by 9 years ago

So I wanted to ability to swap tools when pressing "q", I get no errors (I've never done this before). Am I approaching this the correct way, or am I doing something wrong?

Please note that this is not the whole script

repeat wait()
    Player = game.Players.LocalPlayer
until Player

repeat wait()
leaderstats = Player:FindFirstChild("leaderstats")
until leaderstats

local Mouse = Player:GetMouse()

local Prim = true
local Ak47 = Player.Backpack:FindFirstChild("AK47")
local M9 = Player.Backpack:FindFirstChild("M9")

function SwapW(Ep, De)
    if (Ep) and (De) then
    De.Parent = Player.Backpack
    Player.Character.Humanoid:EquipTool(Ep)
    end
end

leaderstats.InHeist.Changed:connect(function()
    if leaderstats.InHeist.Value == true then
        SwapW(Ak47, M9)
    end
end)

Mouse.KeyDown:connect(function(key)
    if key == "q" then
        if leaderstats.InHeist.Value == true then
        if Prim then
            Prim = false
            SwapW(M9, Ak47)
        elseif not Prim then
            Prim = true
            SwapW(Ak47, M9)
        end
        end
    end
end)
0
Hmm. This may work, although I'm not sure if manually parenting the tool in the Character actually equips it. SlickPwner 534 — 9y
0
Try using :WaitForChild() instead of :FindFirstChild(). (This isn't why it's not working, just a suggestion) Try placing the tools in a model created in the player instead of their Backpack. Tkdriverx 514 — 9y

Answer this question