-- StarterPlayer/StarterPlayerScripts/CurrencyGUI
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- Wait for remotes
local remotes = ReplicatedStorage:WaitForChild("CurrencyRemotes")
local updateCurrency = remotes:WaitForChild("UpdateCurrency")
local currencyGained = remotes:WaitForChild("CurrencyGained")
-- Create main GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "CurrencyGUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = playerGui
-- Currency display frame
local currencyFrame = Instance.new("Frame")
currencyFrame.Size = UDim2.new(0, 200, 0, 50)
currencyFrame.Position = UDim2.new(0, 10, 0, 10)
currencyFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
currencyFrame.BorderSizePixel = 0
currencyFrame.Parent = screenGui
local currencyCorner = Instance.new("UICorner")
currencyCorner.CornerRadius = UDim.new(0, 8)
currencyCorner.Parent = currencyFrame
local coinIcon = Instance.new("ImageLabel")
coinIcon.Size = UDim2.new(0, 30, 0, 30)
coinIcon.Position = UDim2.new(0, 10, 0.5, -15)
coinIcon.BackgroundTransparency = 1
coinIcon.Image = "rbxasset://textures/ui/common/robux.png"
coinIcon.Parent = currencyFrame
local currencyLabel = Instance.new("TextLabel")
currencyLabel.Size = UDim2.new(1, -50, 1, 0)
currencyLabel.Position = UDim2.new(0, 50, 0, 0)
currencyLabel.BackgroundTransparency = 1
currencyLabel.Text = "0"
currencyLabel.TextColor3 = Color3.new(1, 1, 1)
currencyLabel.TextScaled = true
currencyLabel.Font = Enum.Font.SourceSansBold
currencyLabel.Parent = currencyFrame
-- Animation popup template
local function createPopup(amount)
local popup = Instance.new("Frame")
popup.Size = UDim2.new(0, 150, 0, 60)
popup.Position = UDim2.new(0.5, -75, 0.5, -30)
popup.BackgroundColor3 = Color3.new(0.2, 0.8, 0.2)
popup.BorderSizePixel = 0
popup.Parent = screenGui
local popupCorner = Instance.new("UICorner")
popupCorner.CornerRadius = UDim.new(0, 12)
popupCorner.Parent = popup
local popupText = Instance.new("TextLabel")
popupText.Size = UDim2.new(1, 0, 1, 0)
popupText.BackgroundTransparency = 1
popupText.Text = "+" .. tostring(amount) .. " Coins!"
popupText.TextColor3 = Color3.new(1, 1, 1)
popupText.TextScaled = true
popupText.Font = Enum.Font.SourceSansBold
popupText.Parent = popup
-- Create animation
popup.AnchorPoint = Vector2.new(0.5, 0.5)
popup.Size = UDim2.new(0, 0, 0, 0)
-- Tween in
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local tweenIn = TweenService:Create(popup, tweenInfo, {
Size = UDim2.new(0, 150, 0, 60)
})
-- Tween up and fade
local tweenUpInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tweenUp = TweenService:Create(popup, tweenUpInfo, {
Position = UDim2.new(0.5, -75, 0.5, -100),
BackgroundTransparency = 1
})
local tweenTextFade = TweenService:Create(popupText, tweenUpInfo, {
TextTransparency = 1
})
tweenIn:Play()
tweenIn.Completed:Connect(function()
wait(0.5)
tweenUp:Play()
tweenTextFade:Play()
tweenUp.Completed:Connect(function()
popup:Destroy()
end)
end)
end
-- Update currency display
updateCurrency.OnClientEvent:Connect(function(newAmount)
currencyLabel.Text = tostring(newAmount)
end)
-- Show animation when currency gained
currencyGained.OnClientEvent:Connect(function(amount)
createPopup(amount)
-- Pulse animation for currency display
local pulseInfo = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local pulseTween = TweenService:Create(currencyFrame, pulseInfo, {
Size = UDim2.new(0, 220, 0, 55)
})
local pulseBackTween = TweenService:Create(currencyFrame, pulseInfo, {
Size = UDim2.new(0, 200, 0, 50)
})
pulseTween:Play()
pulseTween.Completed:Connect(function()
pulseBackTween:Play()
end)
end)