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

Egg popup that works until i sell the eggs (Simulator game) ?

I made it so that it pops up when you pick up a egg or if you get coins. When i pick up the eggs the popup works fine, but then when i go and sell my eggs to coins and i go back to the eggs and try to pick them up the popup doesn't show on screen. Then randomly it starts working when you pickup af lot of eggs.

Gif that show how it looks like: https://gyazo.com/ade66de5e3beb2264e2c392b428cd326

The script for the popup

wait()
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
if leaderstats then
	local Eggs = leaderstats:FindFirstChild("Eggs")
	if Eggs then
		local lastvalue = Eggs.Value
		Eggs.Changed:connect(function()
			if Eggs.Value >= lastvalue then
				local NewUi = script.TextLabel:Clone()
				NewUi.Parent = script.Parent
				NewUi.Visible = true
				NewUi.Text = "????"..Eggs.Value - lastvalue
				NewUi.Position = UDim2.new(0.477,0,0.460,0)
				NewUi:TweenPosition(UDim2.new(0.066,0,0.405,0),"Out",0.2,true)
				wait(0.95)
				NewUi:Destroy()
				lastvalue = Eggs.Value
			end
		end)
	end
end

1 answer

✓ Accepted answer

My guess is on line 7, you set the lastvalue to however many eggs you last had, and the gui won't show up unless the new egg value is greater than lastvalue.

I'm more of a visual explainer, so here.

What's happening is

before selling: lastvalue = 10 (just an example)

and after selling, lastvalue is still 10 and Eggs.Value is 0.

Now it's checking if the egg value is greater than 10. If it's not, it won't show up. If it is, it'll show up in a bunch.

after selling: lastvalue = 10 | Eggs.Value = 0

So it won't change unless Eggs.Value (0) is > lastvalue (10)


This is just a guess, try it out.

Remove line 7 (local lastvalue = Eggs.Value) and Remove line 9 (if Eggs.Value >= lastvalue then) and Remove line 19 (end)


Hopefully this makes sense. If it doesn't just do what I said in the second section and I'm 75% sure this would work.

~killerbrenden

2 comments

0

Thank you. Had to keep line 7 tho.

0

Alright, no problem! Glad to help. If this worked, select it as an answer so everyone else knows this question has been solved.

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