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

Why does my script only do the "Unequip" section?

Asked by 7 years ago
Edited 7 years ago

Before I added an "Unequip" option to my inventory items, the code worked perfectly fine. Now, it makes my items always do the "Unequip" section of the code. This is the code that I'm using:

EquipButton.MouseButton1Down:connect(function()
    if InventoryItemImage.Image == "rbxassetid://769111505" then --my speed perk
        local Humanoid = game.Players.LocalPlayer.Character.Humanoid
        if SpeedPerkEquiped == false then
            SpeedPerkEquiped = true
            EquipButton.Text = "Unequip"
            if wins.Value >= 50 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 2
            elseif wins.Value >= 45 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.9
            elseif wins.Value >= 40 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.8
            elseif wins.Value >= 35 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.7
            elseif wins.Value >= 30 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.6
            elseif wins.Value >= 25 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.5
            elseif wins.Value >= 20 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.4
            elseif wins.Value >= 15 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.3
            elseif wins.Value >= 10 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.2
            elseif wins.Value >= 5 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed * 1.1
            end
        elseif SpeedPerkEquiped == true then
            SpeedPerkEquiped = false
            EquipButton.Text = "Equip"
            if wins.Value >= 50 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 2
            elseif wins.Value >= 45 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.9
            elseif wins.Value >= 40 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.8
            elseif wins.Value >= 35 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.7
            elseif wins.Value >= 30 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.6
            elseif wins.Value >= 25 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.5
            elseif wins.Value >= 20 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.4
            elseif wins.Value >= 15 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.3
            elseif wins.Value >= 10 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.2
            elseif wins.Value >= 5 then
                Humanoid.WalkSpeed = Humanoid.WalkSpeed / 1.1
            end
        end
    elseif InventoryItemImage.Image == "rbxassetid://833917257" then --my jump perk
        local Humanoid = game.Players.LocalPlayer.Character.Humanoid
        if JumpPerkEquiped == false then
            JumpPerkEquiped = true
            EquipButton.Text = "Unequip"
            if wins.Value >= 50 then
                Humanoid.JumpPower = Humanoid.JumpPower * 2
            elseif wins.Value >= 45 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.9
            elseif wins.Value >= 40 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.8
            elseif wins.Value >= 35 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.7
            elseif wins.Value >= 30 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.6
            elseif wins.Value >= 25 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.5
            elseif wins.Value >= 20 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.4
            elseif wins.Value >= 15 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.3
            elseif wins.Value >= 10 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.2
            elseif wins.Value >= 5 then
                Humanoid.JumpPower = Humanoid.JumpPower * 1.1
            end
        elseif JumpPerkEquiped == true then
            JumpPerkEquiped = false
            EquipButton.Text = "Equip"
            if wins.Value >= 50 then
                Humanoid.JumpPower = Humanoid.JumpPower / 2
            elseif wins.Value >= 45 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.9
            elseif wins.Value >= 40 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.8
            elseif wins.Value >= 35 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.7
            elseif wins.Value >= 30 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.6
            elseif wins.Value >= 25 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.5
            elseif wins.Value >= 20 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.4
            elseif wins.Value >= 15 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.3
            elseif wins.Value >= 10 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.2
            elseif wins.Value >= 5 then
                Humanoid.JumpPower = Humanoid.JumpPower / 1.1
            end
        end
    end
end)

What can I do to make my Speed Perk and my Jump Perk both work again without removing the "Unequip" option?

Any help is appreciated!

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

I have a recommendation for a less messy script, you can use an equation to figure out what their JumpPower, etc. will be using something like:

local function setWalkSpeed(num)
    Humanoid.WalkSpeed = Humanoid.WalkSpeed * (1 + (.1*num/5))
end
if wins.Value >= 5 then
    if wins.Value%5 == 0 then
        setWalkSpeed(wins.Value)
    else
        local numHolder = wins.Value
        for i = 1,(numHolder) do
            if (wins.Value - i)%5 == 0 then
                setWalkSpeed(numHolder) --Number needs to be divisible, so I am passing that to the function!
                break
            end
        end
    end
end

(P.S., that code can replace all of the multiplication stuff for your WalkSpeed! I tested the math and it works., it is a bunch of complicated math but % finds the remainder, so 25%5 = 0 because 25 is divisible by 5, however 11%3 = 2 because 11 can be divided by 3, 3 times [which is 9] and 11-9 = 2)

Also, to what you really want, set up some prints and print the frame's image, etc. to find why it is not working the way you want. Good luck!

0
I don't really understand what this means cause I'm such a noob... marioblast1244 113 — 7y
0
Also, this doesn't tell me how to solve my "Unequip" issue... thanks anyways! marioblast1244 113 — 7y
0
It was just some math I put together to make your script less messy lol, but also put stuff like print("1"), print(value) to see what may be the source of the error. thehybrid576 294 — 7y
Ad

Answer this question