Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script increases the value more than the expected?

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

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

5 comments

0

You shouldn’t be using connect but Connect

0

Opps typo

0

Is there any difference between the deprecated 'connect' and the 'Connect' in terms of functionality?

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

0

Well that I already knew, I was just asking if anything was functionally different. So I'm gonna take that as a 'No'.

This discussion is preserved as it was. New answers, comments, and votes are closed.