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

Script increases the value more than the expected?

Asked by 5 years ago
Edited 5 years ago

The problem is.. That when I catch a fish.. The value of Inventory and the total are increased by a number between 10 to 13 when it's supposed to be increased once... HELP!

            local rate = math.random(10,13) 

            local rod = script.Parent.Rope       

            local Player = game.Players.LocalPlayer

            local fish = Player.leaderstats['Inventory']

            local Total = Player.leaderstats['Total Fish Caught'] 









            rod.Touched:Connect(function(Hit)



            if Hit == game.Workspace["Drown pls"] then 

            while wait(rate)do --Loops every 10 to 13 secs



            print("lel") 

            fish.Value = fish.Value + 1 --increases the Inventory by 1

            Total.Value = fish.Value + 1 --increases the total by 1





              end

             end

            end)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

First of all if you want the rate to be random every time you get a fish, you need to redefine rate inside of the hit event so it's different every time. In terms of your value change, you don't need a while loop at all honestly. I really don't know why it's there. Furthermore, you need a Boolean value to make sure that the Touched event only triggers once, you would also likely want a cooldown for it...

local cooldown = false
local rate = math.random(10,13)

function startCooldown()
    wait(1)
    cooldown = false
end

rod.Touched:Connect(function(Hit)
    rate = math.random(10,13)

    if not cooldown then
        cooldown = true
        startCooldown()

        -- change values here
    end
end)

In your question you said you want the inventory/total to be increased by a number of 10,13. You wouldn't want to add the Inventory and Total by 1, but rather the rate (this will take out the need for the while loop).

0
You shouldn’t be using connect but Connect User#19524 175 — 5y
0
Opps typo climethestair 1663 — 5y
0
Is there any difference between the deprecated 'connect' and the 'Connect' in terms of functionality? climethestair 1663 — 5y
0
one is deprecated one isn’t. one has uppercase C whilst the other doesn’t. one has chance of completely being removed other doesn’t User#19524 175 — 5y
0
Well that I already knew, I was just asking if anything was functionally different. So I'm gonna take that as a 'No'. climethestair 1663 — 5y
Ad

Answer this question