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

Scroll wheel tool change broken, can someone help? [closed]

Asked by
Launderer 343 Moderation Voter
7 years ago
Edited by Pyrondon 7 years ago

Can someone tell me whats wrong with this fix and possibly fix it. I did not make this script btw but I really need it to work. It's supposed to cycle through tools with use of scroll wheel. The forward wheel works with switching weapons, but the scrollwheel back unequips all tools and doesn't equip a new one.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
game:GetService("UserInputService").InputChanged:connect(function(iO,gPE)
    if not gPE then
        if iO.UserInputType == Enum.UserInputType.MouseWheel then
            print(iO.Position.Z)
            local LastTool = nil
            local Pos = 1
            for i,v in pairs(char:GetChildren())do
                if v:IsA'Tool'then
                    LastTool = v
                end
            end
            char.Humanoid:UnequipTools()
            for i,v in pairs(player.Backpack:GetChildren())do
                if v==LastTool then
                    Pos = i
                end
            end
            if iO.Position.Z == 1 then
                if Pos == 1 then
                    Pos = #player.Backpack:GetChildren()
                    char.Humanoid:EquipTool(player.Backpack:GetChildren()[Pos])
                    wait()
                else
                    Pos = Pos-1
                    char.Humanoid:EquipTool(player.Backpack:GetChildren()[Pos])
                    wait()
                end
            elseif iO.Position == -1 then
                if Pos == #player.Backpack:GetChildren() then
                    Pos = 1
                    char.Humanoid:EquipTool(player.Backpack:GetChildren()[Pos])
                    wait()
                else
                    Pos = Pos+1
                    char.Humanoid:EquipTool(player.Backpack:GetChildren()[Pos])
                    wait()
                end
            end
        end
    end
end)
0
Woah, I do not know why the script came out like that... Launderer 343 — 7y
0
Edited for code block. In the future, be sure to enclose your code in a code block by highlighting your code and clicking the blue Lua button included in the editor. Pyrondon 2089 — 7y
0
Stopped reading at "I did not make this script". Goulstem 8144 — 7y

Closed as Not Constructive by Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?