Messy coin animation script

stuff.rbxl (39.3 KB)

Basically, it’s a coin animation and there is one script that I would like to be improved: StarterPlayerScripts > Animation

local remote = game:GetService("ReplicatedStorage"):WaitForChild("AnimationEvent")
local player = game.Players.LocalPlayer
local pg = player:WaitForChild("PlayerGui")
local sui = pg:WaitForChild("Animation")
local zone = sui:WaitForChild("zone")
local frame = script:WaitForChild("frame")

local ts = game:GetService("TweenService")

function TweenTransparency(Thing, Time, Style, Direction, valueArg)
	spawn(function()
	local info = TweenInfo.new(Time, Style, Direction, 0, false, 0)
	local newtween = ts:Create(Thing, info, {TextTransparency = valueArg})
	newtween:Play()
	wait(Time)
	newtween:Destroy()
	end)
end

local function animation(value, image_id, amount_of_images, textcolor, valuename, position)
	local clone = frame:Clone()
	local r1 = math.random(0, 750)
	local r2 = math.random(0, 750)
	
	local award = clone:WaitForChild("award"):WaitForChild("award")
	local white = award:WaitForChild("white")
	local shad = award:WaitForChild("shadow")
	value = ("+"..value.." "..valuename)
	award.Text = value
	white.Text = value
	shad.TextColor = BrickColor.new(textcolor.r/2.5, textcolor.g/2.5, textcolor.b/2.5)
	award.TextColor = textcolor
	shad.Text = value
	clone.Position = UDim2.new(r1/1000, 0, r2/1000, 0)
	for i = 1, amount_of_images do
	local img = clone:WaitForChild("img"):Clone()
	img.Image = "http://www.roblox.com/asset/?id="..image_id
	local r1 = math.random(-9, 65)
	local r2 = math.random(-1, 56)
	local r3 = math.random(25, 34)
	local r4 = math.random(25, 43)
	img.Position = UDim2.new(r1/100, 0, r2/100, 0)
	img.Size = UDim2.new(r3/100, 0, r4/100, 0)
	img.Rotation = math.random(0, 180)
	img.Parent = clone
	img.Visible = true
	end
	clone.Parent = zone
	clone:TweenSize(UDim2.new(0.435, 0, 0.355, 0), "Out", "Linear", 0.1, true)
	wait(0.3)
	award:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2, true)
	wait(0.4)
	white:TweenSize(UDim2.new(1.75, 0, 1.75, 0), "Out", "Linear", 0.5, true)
	TweenTransparency(white, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)	
	wait(0.2)
	for _, v in pairs(clone:GetChildren()) do
		wait(0.05)
		if v.Name == "img" then
			v:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.5, true)
			v:TweenPosition(position, "Out", "Linear", 0.5, true)
		end
	end
	wait(0.5)
	TweenTransparency(award, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)	
	TweenTransparency(shad, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)
	wait(0.5)
	clone:Destroy()
	--warn(value, image_id, amount_of_images)
end

remote.OnClientEvent:Connect(animation)

This is pretty unorganized and if anyone can help me that would be amazing!
It’s a bit messy, and I think it can be improved.

Thanks,
recanman

I just tested the place out and its not even working right

Hm. I’ll look over it, it was working before.

There was a little problem with a path, here is the working version:
popup.rbxl (39.3 KB)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local remote = ReplicatedStorage:WaitForChild("AnimationEvent")

local pg = player:WaitForChild("PlayerGui")
local sui = pg:WaitForChild("Animation")
local zone = sui:WaitForChild("zone")
local frame = script:WaitForChild("frame")

local ts = game:GetService("TweenService")

local function TweenTransparency(Thing, Time, Style, Direction, valueArg)
		spawn(function()
		local info = TweenInfo.new(Time, Style, Direction, 0, false, 0)
		local newtween = ts:Create(Thing, info, {TextTransparency = valueArg})
		newtween:Play()
		wait(Time)
		newtween:Destroy()
	end)
end

local function animation(value, image_id, amount_of_images, textcolor, valuename, position)
		local clone = frame:Clone()
		local r1 = math.random(0, 750)
		local r2 = math.random(0, 750)
		
		local award = clone.awrd.award
		local white = award.white
	    local shad = award.shadow
	    local img = clone.img:Clone()
	
	    local r1 = math.random(-9, 65)
		local r2 = math.random(-1, 56)
		local r3 = math.random(25, 34)
		local r4 = math.random(25, 43)
		value = ("+"..value.." "..valuename)
		award.Text = value
		white.Text = value
		shad.TextColor = BrickColor.new(textcolor.r/2.5, textcolor.g/2.5, textcolor.b/2.5)
		award.TextColor = textcolor
		shad.Text = value
	    clone.Position = UDim2.new(r1/1000, 0, r2/1000, 0)
	
		for i = 1, amount_of_images do
			img.Image = "rbxasset:Id//id="..image_id
			img.Position = UDim2.new(r1/100, 0, r2/100, 0)
			img.Size = UDim2.new(r3/100, 0, r4/100, 0)
			img.Rotation = math.random(0, 180)
			img.Parent = clone
			img.Visible = true
	    end
	
		clone.Parent = zone
		clone:TweenSize(UDim2.new(0.435, 0, 0.355, 0), "Out", "Linear", 0.1, true)
		wait(0.3)
		award:TweenPosition(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.2, true)
		wait(0.4)
		white:TweenSize(UDim2.new(1.75, 0, 1.75, 0), "Out", "Linear", 0.5, true)
		TweenTransparency(white, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)	
	    wait(0.2)
	
		for _, v in pairs(clone:GetChildren()) do
			wait(0.05)
			if v.Name == "img" then
				v:TweenSize(UDim2.new(0, 0, 0, 0), "Out", "Linear", 0.5, true)
				v:TweenPosition(position, "Out", "Linear", 0.5, true)
			end
	    end
	
		wait(0.5)
		TweenTransparency(award, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)	
		TweenTransparency(shad, 0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 1)
		wait(0.5)
		clone:Destroy()
end

remote.OnClientEvent:Connect(animation)

Local functions > functions, nothing else can be done rather to indent your code. All seems fine but still, I would consider it a little messy.

1 Like

Thanks, I normally don’t really script like this but sometimes you get outta your mind :man_shrugging: