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

Whats wrong with this randomizer script?



local player = game.Players:GetPlayerFromCharacter(part.Parent)

local stat = "Cash"

local num = 0

local amount = 20
local amount2 = 50
local amount3 = 175

while true do -- Constantly Changing Number to Help randomize

wait(1)
num = num +1

if num >= 10 then
	
	num = 0
	
end


end

function onTouched(hit)

	if num <= 5 and player then -- If nubmer is any number bellow or equal to 0 they get 25 cash
		
		  
			player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount
		
		
	end
	if num == 6 or 7 or 8 or 9 and player then -- If number is 6-9 they get 50 cash
		


			player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount2
		
		
	end
	if num == 10 and player then -- If number is 10 they get 175 cash!
		

		
			player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount3
		
	end

end

script.Parent.Touched:connect(onTouched)


I see know error in the output box

I dont understand the problem D:

1 comment

0

num = 1, and you check if num = 5 or higher. Also add ends for ifs

1 answer

The problem i noticed was your while true do event. Whenever you say while true do, it will continue to do that action until the event is broken. Therefore the listener will become temporarily nullified



local stat = "Cash"

local num = 0

local amount = 20
local amount2 = 50
local amount3 = 175

while wait(1) do -- Constantly Changing Number to Help randomize
	num = num +1

		if num >= 10 then

  		  	num = 0

		end




script.Parent.Touched:connect(function(hit)
	if hit.Parent.Humanoid then
print("Its a player")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if num <= 5  then


            player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount


    end
    if num == 6 and num <= 9  player then -- If number is 6-9 they get 50 cash



            player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount2


    end
    if num == 10 and player then -- If number is 10 they get 175 cash!



            player.leaderstats[stat].Value = player.leaderstats[stat].Value + amount3
		end
    end

end

end



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