Assistant: 
User: System: You will be given a Luau script (that has been decompiled). You will rename the variables and functions to sound better, make the script more coherent, and add comments to areas of the script. Return the fixed script without adding ``` as we handle that. If no script has been given, do not produce any output. Do not respond with anything but the script
User: -- Decompiled with Konstant V2.1, a fast Luau decompiler made in Luau by plusgiant5 (https://discord.gg/wyButjTMhM)
-- Decompiled on 2024-10-09 12:37:46
-- Luau version 6, Types version 3
-- Time taken: 0.006023 seconds

local ReplicatedStorage_upvr = game:GetService("ReplicatedStorage")
local ItemIDS_upvr = require(ReplicatedStorage_upvr.Modules.ItemIDS)
local Packets_upvr = require(ReplicatedStorage_upvr.Modules.Packets)
local GameUtil_upvr = require(ReplicatedStorage_upvr.Modules.GameUtil)
local tbl_upvr_2 = {}
local tbl_upvr_3 = {}
local tbl_upvr_4 = {}
local Players_upvr = game:GetService("Players")
local EntityHandler_upvr = require(script.Parent.Parent.EntityHandler)
local function playerInBallista_upvr(arg1) -- Line 70, Named "playerInBallista"
	--[[ Upvalues[2]:
		[1]: Players_upvr (readonly)
		[2]: EntityHandler_upvr (readonly)
	]]
	local any_GetPlayerFromCharacter_result1 = Players_upvr:GetPlayerFromCharacter(arg1)
	if not any_GetPlayerFromCharacter_result1 then return end
	local InBallista = any_GetPlayerFromCharacter_result1:GetAttribute("InBallista")
	if not InBallista then return end
	local any_GetEntity_result1 = EntityHandler_upvr.GetEntity(InBallista)
	if not any_GetEntity_result1 then return end
	local Projectile = any_GetEntity_result1:GetAttribute("Projectile")
	if not Projectile then return end
	local ProjectileDamageName = any_GetEntity_result1:GetAttribute("ProjectileDamageName")
	if not ProjectileDamageName then return end
	return Projectile, ProjectileDamageName
end
local SkinData_upvr = require(ReplicatedStorage_upvr.Modules.SkinData)
local function getProjectileName_upvr(arg1, arg2, arg3) -- Line 89, Named "getProjectileName"
	--[[ Upvalues[3]:
		[1]: ItemIDS_upvr (readonly)
		[2]: GameUtil_upvr (readonly)
		[3]: SkinData_upvr (readonly)
	]]
	-- KONSTANTERROR: [0] 1. Error Block 14 start (CF ANALYSIS FAILED)
	if arg2 and arg3 then
		return arg2, arg3
	end
	-- KONSTANTERROR: [0] 1. Error Block 14 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [68] 48. Error Block 11 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [68] 48. Error Block 11 end (CF ANALYSIS FAILED)
	-- KONSTANTERROR: [39] 27. Error Block 5 start (CF ANALYSIS FAILED)
	-- KONSTANTERROR: Expression was reused, decompilation is incorrect
	-- KONSTANTERROR: [39] 27. Error Block 5 end (CF ANALYSIS FAILED)
end
local function _(arg1) -- Line 116, Named "getProjectileTemplate"
	--[[ Upvalues[1]:
		[1]: ReplicatedStorage_upvr (readonly)
	]]
	return ReplicatedStorage_upvr.Projectiles:FindFirstChild(arg1):Clone()
end
local function _(arg1, arg2, arg3, arg4) -- Line 120, Named "getPositionAtTime"
	return arg2 + arg3 * arg1 + arg4 * arg1 ^ 2 / 2
end
local function _(arg1) -- Line 125, Named "getPhysicalTool"
	--[[ Upvalues[1]:
		[1]: GameUtil_upvr (readonly)
	]]
	local equipped_2 = GameUtil_upvr.Data.equipped
	if not equipped_2 then return end
	local name = GameUtil_upvr.Data.toolbar[equipped_2].name
	if not name then return end
	return arg1.Tools:FindFirstChild(name)
end
local function getEntityID_upvr(arg1) -- Line 135, Named "getEntityID"
	if arg1 == workspace.Terrain then
		return workspace.Terrain:GetAttribute("EntityID")
	end
	local class_Model = arg1:FindFirstAncestorWhichIsA("Model")
	if not class_Model or class_Model == workspace then return end
	local EntityID = class_Model:GetAttribute("EntityID")
	if not EntityID then return end
	return EntityID
end
local tbl_upvr = {
	BrickColor = true;
	Color = true;
	Material = true;
	Reflectance = true;
	Transparency = true;
}
local module_upvr = {}
module_upvr.__index = module_upvr
local ItemData_upvr = require(ReplicatedStorage_upvr.Modules.ItemData)
function module_upvr.new(arg1) -- Line 160
	--[[ Upvalues[10]:
		[1]: ItemIDS_upvr (readonly)
		[2]: ItemData_upvr (readonly)
		[3]: playerInBallista_upvr (readonly)
		[4]: getProjectileName_upvr (readonly)
		[5]: ReplicatedStorage_upvr (readonly)
		[6]: GameUtil_upvr (readonly)
		[7]: tbl_upvr (readonly)
		[8]: module_upvr (readonly)
		[9]: tbl_upvr_2 (readonly)
		[10]: Packets_upvr (readonly)
	]]
	local playerInBallista_upvr_result1, playerInBallista_upvr_result2 = playerInBallista_upvr(arg1.character)
	local getProjectileName_upvr_result1, getProjectileName_upvr_result2 = getProjectileName_upvr(arg1, playerInBallista_upvr_result1, playerInBallista_upvr_result2)
	local clone = ReplicatedStorage_upvr.Projectiles:FindFirstChild(getProjectileName_upvr_result1):Clone()
	local equipped = GameUtil_upvr.Data.equipped
	local var35
	if not equipped then
		var35 = nil
	else
		local name_2 = GameUtil_upvr.Data.toolbar[equipped].name
		if not name_2 then
			var35 = nil
		else
			var35 = arg1.character.Tools:FindFirstChild(name_2)
		end
	end
	if var35 and not playerInBallista_upvr_result1 then
		for i, v in var35:GetAttributes(), nil do
			if tbl_upvr[i] then
				clone[i] = v
			end
		end
	end
	local var37 = ItemData_upvr[getProjectileName_upvr_result2]
	local var38 = (ItemData_upvr[ItemIDS_upvr[arg1.toolID]].velocityMagnitude + (var37.additionalVelocity or 0)) * arg1.drawStrength
	local RaycastParams_new_result1 = RaycastParams.new()
	RaycastParams_new_result1.FilterDescendantsInstances = {workspace.Projectiles, workspace.ClimbableRegions, arg1.character}
	RaycastParams_new_result1.FilterType = Enum.RaycastFilterType.Exclude
	RaycastParams_new_result1.IgnoreWater = true
	local workspace_GetServerTimeNow_result1_2 = workspace:GetServerTimeNow()
	local setmetatable_result1 = setmetatable({}, module_upvr)
	setmetatable_result1.projectileName = getProjectileName_upvr_result2
	setmetatable_result1.projectile = clone
	setmetatable_result1.gravity = Vector3.yAxis * -122.2 + Vector3.yAxis * (var37.additionalGravity or 0)
	setmetatable_result1.velocityMagnitude = var38
	setmetatable_result1.initialVelocity = var38
	setmetatable_result1.origin = arg1.originCF.Position
	setmetatable_result1.position = arg1.originCF.Position
	setmetatable_result1.velocity = arg1.originCF.LookVector * setmetatable_result1.velocityMagnitude
	setmetatable_result1.velocityLossPerBounce = var37.velocityLoss or 0.25
	setmetatable_result1.projectileCanBounce = var37.projectileCanBounce or false
	setmetatable_result1.projectileMaximumBounces = var37.maximumBounces or 4
	setmetatable_result1.projectileBounces = 0
	setmetatable_result1.createTime = workspace_GetServerTimeNow_result1_2
	setmetatable_result1.lastUpdate = workspace_GetServerTimeNow_result1_2
	setmetatable_result1.isModel = clone:IsA("Model")
	setmetatable_result1.id = arg1.id
	setmetatable_result1.owned = arg1.owner
	setmetatable_result1.raycastParams = RaycastParams_new_result1
	setmetatable_result1.projectile:PivotTo(arg1.originCF)
	setmetatable_result1.projectile.Parent = workspace.Projectiles
	tbl_upvr_2[arg1.id] = setmetatable_result1
	if setmetatable_result1.owned then
		Packets_upvr.CreateProjectile.send({
			originCF = arg1.originCF;
			drawStrength = arg1.drawStrength;
			toolID = arg1.toolID;
			timeStamp = workspace_GetServerTimeNow_result1_2;
			projectileID = ItemIDS_upvr[getProjectileName_upvr_result2];
			id = arg1.id;
		})
	end
	return setmetatable_result1
end
function module_upvr.getLifeTime(arg1, arg2) -- Line 245
	local var44 = arg2
	if not var44 then
		var44 = workspace:GetServerTimeNow()
	end
	return var44 - arg1.createTime
end
function module_upvr.getPosition(arg1, arg2) -- Line 249
	local var45 = arg1.lastUpdate - arg1.createTime
	local var46 = arg2 - arg1.createTime
	return arg1.origin + arg1.velocity * var45 + arg1.gravity * var45 ^ 2 / 2, arg1.origin + arg1.velocity * var46 + arg1.gravity * var46 ^ 2 / 2
end
function module_upvr.tick(arg1) -- Line 256
	--[[ Upvalues[4]:
		[1]: tbl_upvr_3 (readonly)
		[2]: tbl_upvr_4 (readonly)
		[3]: getEntityID_upvr (readonly)
		[4]: Packets_upvr (readonly)
	]]
	local workspace_GetServerTimeNow_result1 = workspace:GetServerTimeNow()
	if 10 < arg1:getLifeTime(workspace_GetServerTimeNow_result1) or arg1.velocityMagnitude <= 0 or arg1.projectileMaximumBounces < arg1.projectileBounces then
		arg1:destroy()
	else
		local any_getPosition_result1, any_getPosition_result2 = arg1:getPosition(workspace_GetServerTimeNow_result1)
		local var50 = any_getPosition_result2
		arg1.position = any_getPosition_result2
		arg1.lastUpdate = workspace_GetServerTimeNow_result1
		if arg1.isModel then
			var50 = arg1.projectile.PrimaryPart
		else
			var50 = arg1.projectile
		end
		table.insert(tbl_upvr_3, var50)
		table.insert(tbl_upvr_4, CFrame.lookAt(any_getPosition_result1, var50))
		local var51 = any_getPosition_result2 - any_getPosition_result1
		if var51.Magnitude < 0 then return end
		local workspace_Raycast_result1 = workspace:Raycast(any_getPosition_result1, var51.Unit * (var51.Magnitude + 0.1), arg1.raycastParams)
		if not workspace_Raycast_result1 then return end
		local Position = workspace_Raycast_result1.Position
		local Normal = workspace_Raycast_result1.Normal
		if arg1.projectileCanBounce then
			arg1.position = Position
			arg1.origin = Position
			arg1.createTime = workspace_GetServerTimeNow_result1
			arg1.projectileBounces += 1
			arg1.velocityMagnitude -= arg1.initialVelocity * arg1.velocityLossPerBounce
			if 0 < arg1.velocityMagnitude and arg1.projectileBounces <= arg1.projectileMaximumBounces then
				arg1.velocity = (var51 - (2) * (var51:Dot(Normal) * Normal)).Unit * arg1.velocityMagnitude
			else
				arg1:destroy()
			end
		else
			arg1:destroy()
		end
		if not arg1.owned then return end
		local getEntityID_upvr_result1 = getEntityID_upvr(workspace_Raycast_result1.Instance)
		if not getEntityID_upvr_result1 then return end
		Packets_upvr.ProjectileImpact.send({
			entityID = getEntityID_upvr_result1;
			position = Position;
			direction = var51;
			normal = Normal;
			id = arg1.id;
			timeStamp = workspace_GetServerTimeNow_result1;
		})
	end
end
local DebrisService_upvr = require(ReplicatedStorage_upvr.Modules.DebrisService)
function module_upvr.destroy(arg1) -- Line 322
	--[[ Upvalues[2]:
		[1]: DebrisService_upvr (readonly)
		[2]: tbl_upvr_2 (readonly)
	]]
	if not arg1.isModel then
		arg1.projectile.Transparency = 1
	end
	for _, v_2 in arg1.projectile:GetDescendants() do
		if v_2:IsA("ParticleEmitter") then
			v_2.Enabled = false
		end
		if v_2:IsA("BasePart") then
			v_2.Transparency = 1
		end
	end
	DebrisService_upvr:AddItem(arg1.projectile, 2)
	tbl_upvr_2[arg1.id] = nil
end
require(ReplicatedStorage_upvr.Modules.Clock)(function() -- Line 341
	--[[ Upvalues[3]:
		[1]: tbl_upvr_2 (readonly)
		[2]: tbl_upvr_3 (readonly)
		[3]: tbl_upvr_4 (readonly)
	]]
	for _, v_3 in tbl_upvr_2 do
		v_3:tick()
	end
	workspace:BulkMoveTo(tbl_upvr_3, tbl_upvr_4, Enum.BulkMoveMode.FireCFrameChanged)
	table.clear(tbl_upvr_3)
	table.clear(tbl_upvr_4)
end)
return module_upvr
Assistant:
Assistant: