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)
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).