Strength pop up not working

  1. What do you want to achieve?

I am trying to make a strength pop up gui but every time I sell the gui goes.

  1. What is the issue?

The issue is when I sell the strength the strength goes back to 0 but the gui doesn’t show unless I go back to number I sold for!

  1. What solutions have you tried so far?

Finding a solution!

local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Strength")
local module = require(game.ReplicatedStorage.Abbreviations)
local dif = 0
delay(.25, function()
	dif = cash.Value
end)

cash.Changed:Connect(function()
	if dif ~= cash.Value and dif <= cash.Value then
		local random = math.random(1, 900)
		local xnew = random / 1000
		local new = script:WaitForChild("Strength"):Clone()
		new:WaitForChild("StrengthInfo").Text = "+"..module.abbreviate(cash.Value - dif)
		local NewRandom = Random.new()
		new.Position = UDim2.new(NewRandom:NextNumber(0, 1), 0, NewRandom:NextNumber(0, 1), 0)
		new.Parent = script.Parent
		dif = cash.Value
		local TweenService = game:GetService("TweenService")

		local tween = TweenService:Create(new, TweenInfo.new(1), {Rotation = 360})

		wait(1)
		new:TweenSize(UDim2.new(0.056, 0, 0.099, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
		wait(0.3)
		new:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
		wait(0.2)
		new.Parent = nil
	end
end)

Thank you advance!

You have the dif <= cash.Value in the if statement which makes it not show the GUI if the new cash amount is higher than the old one. Hope this helps!

But if I now go to sell it shows like the amount of strength “-” I just want it show strength gained not lost!

Thank you for trying to help though!

Then you can try putting a minus (not as string) before the number so it will invert or use math.abs().
Also you shouldn’t delete instances by making their parent nil, you should use :Destroy() or just set them as nil.

cash.Value is the changed cash value, dif is the starting cash value.

local players = game:GetService("Players")
local storage = game:GetService("ReplicatedStorage")
local tweens = game:GetService("TweenService")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Strength")
local module = require(storage:WaitForChild("Abbreviations"))
local dif = cash.Value or 0

cash.Changed:Connect(function(newVal)
	if dif ~= newVal and dif <= newVal then
		local old = script:WaitForChild("Strength")
		local new = script:WaitForChild("Strength"):Clone()
		new:WaitForChild("StrengthInfo").Text = "+"..module.abbreviate(newVal - dif)
		local NewRandom = Random.new()
		new.Position = UDim2.new(NewRandom:NextNumber(0, 1), 0, NewRandom:NextNumber(0, 1), 0)
		new.Parent = script
		dif = newVal
		local tween = tweens:Create(new, TweenInfo.new(1), {Rotation = 360})
		task.wait(1)
		new:TweenSize(UDim2.new(0.056, 0, 0.099, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
		task.wait(0.3)
		new:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
		task.wait(0.3)
		old:Destroy()
	end
end)

Is this what you’re trying to achieve?

No but it is fixed thank you for helping