- What do you want to achieve?
A coin pop up system that only shows the increase value.
- What is the issue?
The issue is it shows the increase and decrease.
- 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 Coins = leaderstats:WaitForChild("Coins")
local module = require(game.ReplicatedStorage.Abbreviations)
local dif = 0
delay(.25, function()
dif = Coins.Value
end)
Coins.Changed:Connect(function()
if dif ~= Coins.Value then
local random = math.random(1, 900)
local xnew = random / 1000
local new = script:WaitForChild("Coins"):Clone()
new:WaitForChild("CoinsInfo").Text = "+"..module.abbreviate(Coins.Value - dif)
local NewRandom = Random.new()
new.Position = UDim2.new(NewRandom:NextNumber(0, 0.9), 0, NewRandom:NextNumber(0, 0.9), 0)
new.Parent = script.Parent
dif = Coins.Value
local TweenService = game:GetService("TweenService")
local tween = TweenService: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:TweenPosition(UDim2.new(0.025, 0,0.305, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
task.wait(0.2)
new:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
task.wait(0.2)
new.Parent = nil
end
end)
Thank you in advance!
I did this before, except instead of using .Changed
, I just made it pop up when I added coins.
e.g.
Coins.Value += 5
--Make the text pop up here.
1 Like
I think I know what you mean but isn’t there a more efficient way of doing this like just from 1 script it works for the full game?
I guess it’s more efficient to do it just from 1 script. I’ll go think about other solutions.
1 Like
Wait I think I got a method. You would need 2 data store values for this. One data store value would be Coins and the other would be PrevCoins. When you add coins, you would have to set prevcoins to the current amount of coins. Then add the amount of coins to the current coins which would be coins. Therefore you would have the previous amount of coins and the current amount of coins. If the current amount of coins is more than previous amount, then it added. If it’s the opposite, it subtracted.
Example:
local coins = coins.value
local previousCoins = prevCoins.value
previousCoins.value = coins
coins += (amount of coins to add)
previousCoins = prevCoins.value
if coins > previousCoins then
—it added
else
—it subtracted
Sorry if this is too much or doesn’t make sense. I was in a rush. But I hope it helps!
1 Like
local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local leaderstats = plr:WaitForChild("leaderstats")
local Coins = leaderstats:WaitForChild("Coins")
local module = require(game.ReplicatedStorage.Abbreviations)
local dif = Coins.Value
Coins.Changed:Connect(function(NewValue)
if NewValue - dif > 0 then -- this starts when player gets money
local random = math.random(1, 900)
local xnew = random / 1000
local new = script:WaitForChild("Coins"):Clone()
new:WaitForChild("CoinsInfo").Text = "+"..module.abbreviate(NewValue - dif)
local NewRandom = Random.new()
new.Position = UDim2.new(NewRandom:NextNumber(0, 0.9), 0, NewRandom:NextNumber(0, 0.9), 0)
new.Parent = script.Parent
dif = Coins.Value
local TweenService = game:GetService("TweenService")
local tween = TweenService: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:TweenPosition(UDim2.new(0.025, 0,0.305, 0),Enum.EasingDirection.In,Enum.EasingStyle.Linear,0.2)
task.wait(0.2)
new:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, 0.3, true)
task.wait(0.2)
new.Parent = nil
dif = NewValue
elseif dif - NewValue < 0 then -- when player lose money
print("Lost "..(NewValue - dif)..": Amount of Money")
end
end)
5 Likes