Function result isnt updating

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am making a RNG game (gambling🤑) similar to Sols RNG
  2. What is the issue? Include screenshots / videos if possible!
    Basically, after rolling the function gets an aura and waits till you press either button before sending the aura or that you skipped to the other function. That function doesn’t wait and gets nil as its result.
local highestAura = nil
local gen = 1
local cooldownDecreaser = 1
local luckMultiplier = 1
local rolling = false
local function roll(fake)
	local result = math.random(1, 100 * gen)
	local aura
	script.Parent.Parent.AuraGained.Visible = true
	script.Parent.Parent.AuraGained.Position = UDim2.fromScale(0.4, 0.6)
	
	if result <= (1 * gen * luckMultiplier) then
		aura = "Mythic"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.JosefinSans
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("Royal purple")
	elseif result <= (5 * gen * luckMultiplier) then
		aura = "Legendary"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.Oswald
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("Deep orange")
	elseif result <= (25 * gen * luckMultiplier) then
		aura = "Epic"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.SourceSans
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("White")
	elseif result <= (50 * gen * luckMultiplier) then
		aura = "Rare"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.SourceSans
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("White")
	elseif result <= (75 * gen * luckMultiplier) then
		aura = "Uncommon"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.SourceSans
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("White")
	elseif result <= (100 * gen * luckMultiplier) then
		aura = "Common"
		script.Parent.Parent.AuraGained.Text = aura
		script.Parent.Parent.AuraGained.Font = Enum.Font.SourceSans
		script.Parent.Parent.AuraGained.TextColor = BrickColor.new("White")
	end
	local info = TweenInfo.new(0.1 * cooldownDecreaser, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0)
	local position = {Position = UDim2.fromScale(0.4, 0.675)}
	local tween = game.TweenService:Create(script.Parent.Parent.AuraGained, info, position)
	tween:Play()
	tween.Completed:Connect(function()
		if fake ~= true then 
	
			script.Parent.Parent.EquipButton.Visible = true

			script.Parent.Parent.SkipButton.Visible = true
			script.Parent.Parent.SkipButton.Activated:Connect(function()
				script.Parent.Parent.EquipButton.Visible = false

				script.Parent.Parent.SkipButton.Visible = false
				print("a")
				return "Skipped"
			end)
			script.Parent.Parent.EquipButton.Activated:Connect(function()
				script.Parent.Parent.EquipButton.Visible = false

				script.Parent.Parent.SkipButton.Visible = false
				print("b")
				return aura
			end)
		end
	end)
	
end
function fullRoll()
	if not rolling then
		rolling = true
		for i = 1, 10 do
			roll(true)
			task.wait(0.2 / cooldownDecreaser)
		end 
		local result = roll()
		print(result)
		repeat
			task.wait()
		until result ~= nil
		print("done")
		if result ~= "Skipped" then
			print(result)
			game.ReplicatedStorage.AuraFunction:InvokeServer(result)
		end
		task.wait(2 / cooldownDecreaser)
		rolling = false
		
		
	end
end
script.Parent.Activated:Connect(fullRoll)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried searching across the dev forum, I also added a repeat loop waiting until the value changes but it doesn’t
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

the answer might be very simple but its 8 30 and im very sleepy

why are you doing your roll on the client? a hacker can abuse that, other than that the logic is somewhat bad, consider just making a cache of whatever the user rolled, and then once they pick a option find whatever the rolled in the cache and use that

first off this is a simple project im doing for fun
second of all this game isnt even competitive and i dont really care as leaderboards wont be a thing
third of all this doesnt answer my question whatsoever

If your doing it for fun, it’s still good to actually try so you can learn… if you don’t want to learn then asking questions like these are pointless

I literally answered your question with this?

local function returnSomethingPlease()
   task.delay(100, function()
      return true
   end
end

local something = returnSomethingPlease()
--// results in it being nil even if after 100 seconds you return it, thats just how it is.
1 Like

oh sorry didnt realize i thought you meant something else

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.