Pinkstack/roblox-luau-corpus-text huggingface dataset:
--DO NOT CHANGE ANYTHING INSIDE OF THIS SCRIPT BESIDES WHAT YOU ARE TOLD TO UNLESS YOU KNOW WHAT YOU'RE DOING OR THE SCRIPT WILL NOT WORK!!


local hitPart = script.Parent
local debounce = true
local tool = game.ServerStorage.PieBomb -- Change "Sword" to the name of your tool, make sure your tool is in ServerStorage

hitPart.Touched:Connect(function(hit)
	if debounce == true then
		if hit.Parent:FindFirstChild("Humanoid") then
			local plr = game.Players:FindFirstChild(hit.Parent.Name)
			if plr then
				debounce = false
				hitPart.BrickColor = BrickColor.new("Bright red")
				tool:Clone().Parent = plr.Backpack
				wait(3) -- Change "3" to however long you want the player to have to wait before they can get the tool again
				debounce = true
				hitPart.BrickColor = BrickColor.new("Bright green")
			end
		end
	end
end)
--// B_arocena


local _C = {}

function _C.RemoveHat(hts)
	for i=1, #hts do 
	if (hts[i].className == "Accessory") or (hts[i].className == "Hat") then 
	hts[i]:remove() 
end
end
end



function _C.ShirtPant (Outfit,Player,CClass)
	if CClass.Current.Value < CClass.Max.Value then
	if Player.Class.Current_Class.Value == "None" then
	if Outfit.Shirt.Value ~= 0 then
		Player.Character:WaitForChild("Shirt"):destroy()
		game:GetService("InsertService"):LoadAsset(Outfit.Shirt.Value).Shirt.Parent = Player.Character	
	end
	if Outfit.Pant.Value ~= 0 then
		Player.Character:WaitForChild("Pants"):destroy()
		game:GetService("InsertService"):LoadAsset(Outfit.Pant.Value).Pants.Parent = Player.Character
	end
	end
	end
end



function _C.GiveHat (s,CSYS,Player,Outfit,CClass)
if CClass.Current.Value < CClass.Max.Value then
	if Player.Class.Current_Class.Value == "None" then
if s.Value ~= "" then	
local g = CSYS.HATS[s.Value]:clone()
		g.Parent = Player.Character
		local C = g:GetChildren()
		for i=1, #C do
			if C[i]:IsA("BasePart")  then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
				g.Middle.Transparency = 1
			end
				local Y = Instance.new("Weld")
				local Result = (s.Value):match("BACKPACK")
				if Result == nil then
				Y.Part0 = Player.Character.Head
				else
				Y.Part0 = Player.Character.Torso
				end
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
end
end
end
end

function _C.giveclass (CClass,Player,CLNAME,Tools,Gui)
	if CClass.Current.Value < CClass.Max.Value then
	if Player.Class.Current_Class.Value == "None" then
	Player.Class.Current_Class.Value = CLNAME
	CClass.Current.Value = CClass.Current.Value + 1
	for i = 1, #Tools do
    Tools[i]:Clone().Parent = Player.Backpack
end
Gui:Destroy()
end
end
end

return _C
--[[Status Vars]]



	local _IsOn = _Tune.AutoStart
	if _Tune.AutoStart then script.Parent.IsOn.Value=true end
	
	local _GSteerT=0
	local _GSteerC=0
	local _GThrot=0
	local _GThrotShift=1
	local _GBrake=0
	
	local _ClutchOn = true
	local _ClPressing = false
	local _RPM = 0
	local _HP = 0
	local _OutTorque = 0
	local _CGear = 0
	local _PGear = _CGear
	local _spLimit = 0
	
	local _TMode = _Tune.TransModes[1]
	
	local _MSteer = false
	local _SteerL = false
	local _SteerR = false
	local _PBrake = false
	local _TCS = _Tune.TCSEnabled
	local _TCSActive = false
	local _TCSAmt = 0
	local _ABS = _Tune.ABSEnabled
	local _ABSActive = false
	
	local FlipWait=tick()
	local FlipDB=false
	
	local _InControls = false
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------


PainKillerQnt.Text 	= PainKiller.Value
BandageQnt.Text 	= Bandage.Value
EnergyShotQnt.Text 	= EnergyShot.Value
EpinephrineQnt.Text = Epinephrine.Value
MorphineQnt.Text 	= Morphine.Value
SplintQnt.Text 		= Splint.Value
TourniquetQnt.Text 	= Tourniquet.Value

PainKiller.Changed:Connect(function()
	PainKillerQnt.Text = PainKiller.Value
end)

Bandage.Changed:Connect(function()
	BandageQnt.Text = Bandage.Value
end)

Splint.Changed:Connect(function()
	SplintQnt.Text = Splint.Value
end)

Tourniquet.Changed:Connect(function()
	TourniquetQnt.Text = Tourniquet.Value
end)

EnergyShot.Changed:Connect(function()
	EnergyShotQnt.Text = EnergyShot.Value
end)

Epinephrine.Changed:Connect(function()
	EpinephrineQnt.Text = Epinephrine.Value
end)

Morphine.Changed:Connect(function()
	MorphineQnt.Text = Morphine.Value
end)

SacoDeSangue.Changed:Connect(function()
	SacoDeSangueQnt.Text = SacoDeSangue.Value
end)

Target.Changed:Connect(function(Valor)
	if Valor == nil then
		PTexto.Text =  player.Name
	else
		PTexto.Text =  Valor.Name
	end
end)
------------------------------------------------------------------------
--
-- * used in (lparser) luaY:closelistfield(), luaY:lastlistfield()
------------------------------------------------------------------------


function luaK:setlist(fs, base, nelems, tostore)
  local c = math.floor((nelems - 1)/luaP.LFIELDS_PER_FLUSH) + 1
  local b = (tostore == luaY.LUA_MULTRET) and 0 or tostore
  assert(tostore ~= 0)
  if c <= luaP.MAXARG_C then
    self:codeABC(fs, "OP_SETLIST", base, b, c)
  else
    self:codeABC(fs, "OP_SETLIST", base, b, 0)
    self:code(fs, luaP:CREATE_Inst(c), fs.ls.lastline)
  end
  fs.freereg = base + 1  -- free registers with list values
end

return function(a) luaY = a return luaK end
-- connect events


Enemy.Died:connect(onDied)
Enemy.Running:connect(onRunning)
Enemy.Jumping:connect(onJumping)
Enemy.Climbing:connect(onClimbing)
Enemy.GettingUp:connect(onGettingUp)
Enemy.FreeFalling:connect(onFreeFall)
Enemy.FallingDown:connect(onFallingDown)
Enemy.Seated:connect(onSeated)
Enemy.PlatformStanding:connect(onPlatformStanding)
Enemy.Swimming:connect(onSwimming)
--[[for x = 1, 50 do
s.Pitch = s.Pitch + 0.01
s:play()
wait(0.001)
end]]


for x = 50, 120 do
s:play()
wait(0.001)
end
for x = 50, 120 do
s.Pitch = s.Pitch - 0.0020
s:play()
wait(0.001)
end
wait()
end
--[[
	All configurations are located in the "Settings" Module script.
	Please don't edit this script unless you know what you're doing.
--]]



local Tycoons = {}

local RebirthSettings = require(script.Parent.SaveTrigger.Settings)
local Teams = game:GetService('Teams')
local Settings = require(script.Parent.Settings)
local BC = BrickColor

local playerMoney = game:GetService("ServerStorage"):FindFirstChild("PlayerMoney")
local PlayerStatManager = require(script.Parent:WaitForChild("PlayerStatManager"))

print("Running Core_Handler_New-----------")
if playerMoney == nil then
	print("playerMoney == nil ------------")
	local Storage = Instance.new('Folder', game.ServerStorage)
	Storage.Name = "PlayerMoney"
end

Instance.new('Model',workspace).Name = "PartStorage" --  parts dropped go in here to be killed >:)


function returnColorTaken(color)
	for i,v in pairs(Teams:GetChildren()) do
		if v:IsA('Team') then
			if v.TeamColor == color then
				return true
			end
		end
	end
	return false
end
-- main:


physicsService:CreateCollisionGroup("Characters")
physicsService:CollisionGroupSetCollidable("Characters", "Characters", false)

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(handleCharacter)
end)

for i, v in pairs(game.ReplicatedStorage.Enemys:GetChildren()) do
	if v:IsA("Model") then
		handleNPcs(v)
	end
end

for i, v in pairs(game.ReplicatedStorage.Units:GetChildren()) do
	if v:IsA("Model") then
		handleNPcs(v)
	end
end
-- RCM Settings V



self.WeaponWeight		= 4 -- Weapon weight must be enabled in the Config module

self.ShellEjectionMod	= true

self.Holster			= true
self.HolsterPoint		= "Torso"
self.HolsterCFrame		= CFrame.new(0.65,0.1,-0.8) * CFrame.Angles(math.rad(-90),math.rad(15),math.rad(75))

self.FlashChance = 4 -- 0 = no muzzle flash, 10 = Always muzzle flash

self.ADSEnabled 		= { -- Ignore this setting if not using an ADS Mesh
	true, -- Enabled for primary sight
	false} -- Enabled for secondary sight (T)

self.ExplosiveAmmo		= false -- Enables explosive ammo
self.ExplosionRadius	= 70 -- Radius of explosion damage in studs
self.ExplosionType		= "Default" -- Which explosion effect is used from the HITFX Explosion folder
self.IsLauncher			= true -- For RPG style rocket launchers

self.EjectionOverride	= nil -- Don't touch unless you know what you're doing with Vector3s

return self
-- ~60 c/s


game["Run Service"].Stepped:connect(function()	
	--RPM
	RPM()
	
	--Update External Values
	_IsOn = script.Parent.IsOn.Value
	_InControls = script.Parent.ControlsOpen.Value
	script.Parent.Values.Gear.Value = _CGear
	script.Parent.Values.RPM.Value = _RPM
	script.Parent.Values.Horsepower.Value = _HP
	script.Parent.Values.Torque.Value = _HP * _Tune.EqPoint / _RPM
	script.Parent.Values.TransmissionMode.Value = _TMode
	script.Parent.Values.Throttle.Value = _GThrot
	script.Parent.Values.Brake.Value = _GBrake
	script.Parent.Values.SteerC.Value = _GSteerC*(1-math.min(car.DriveSeat.Velocity.Magnitude/_Tune.SteerDecay,1-(_Tune.MinSteer/100)))
	script.Parent.Values.SteerT.Value = _GSteerT
	script.Parent.Values.PBrake.Value = _PBrake
	script.Parent.Values.TCS.Value = _TCS
	script.Parent.Values.TCSActive.Value = _TCSActive
	script.Parent.Values.ABS.Value = _ABS
	script.Parent.Values.ABSActive.Value = _ABSActive
	script.Parent.Values.Velocity.Value = car.DriveSeat.Velocity
end)
--[=[
	Binds the given update function to [RunService.Stepped]. See [StepUtils.bindToRenderStep] for details.


	:::tip
	Be sure to call the disconnect function when cleaning up, otherwise you may memory leak.
	:::

	@param update () -> boolean -- should return true while it needs to update
	@return (...) -> () -- Connect function
	@return () -> () -- Disconnect function
]=]


function StepUtils.bindToStepped(update)
	return StepUtils.bindToSignal(RunService.Stepped, update)
end
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------


	
local toolAnimName = ""
local toolOldAnimTrack = nil
local toolAnimTrack = nil
local currentToolAnimKeyframeHandler = nil
	
function toolKeyFrameReachedFunc(frameName)
	if (frameName == "End") then
		--		print("Keyframe : ".. frameName)
		local repeatAnim = stopToolAnimations()
		playToolAnimation(repeatAnim, 0.0, Humanoid)
	end
end
	
	
function playToolAnimation(animName, transitionTime, humanoid)
	if (animName ~= toolAnimName) then		 
			
		if (toolAnimTrack ~= nil) then
			toolAnimTrack:Stop()
			toolAnimTrack:Destroy()
			transitionTime = 0
		end
			
		local roll = math.random(1, animTable[animName].totalWeight) 
		local origRoll = roll
		local idx = 1
		while (roll > animTable[animName][idx].weight) do
			roll = roll - animTable[animName][idx].weight
			idx = idx + 1
		end
		--		print(animName .. " * " .. idx .. " [" .. origRoll .. "]")
		local anim = animTable[animName][idx].anim
			
		-- load it to the humanoid; get AnimationTrack
		toolOldAnimTrack = toolAnimTrack
		toolAnimTrack = humanoid:LoadAnimation(anim)
		 
		-- play the animation
		toolAnimTrack:Play(transitionTime)
		toolAnimName = animName
			
		currentToolAnimKeyframeHandler = toolAnimTrack.KeyframeReached:connect(toolKeyFrameReachedFunc)
	end
end
	
function stopToolAnimations()
	local oldAnim = toolAnimName
		
	if (currentToolAnimKeyframeHandler ~= nil) then
		currentToolAnimKeyframeHandler:disconnect()
	end
		
	toolAnimName = ""
	if (toolAnimTrack ~= nil) then
		toolAnimTrack:Stop()
		toolAnimTrack:Destroy()
		toolAnimTrack = nil
	end
		
		
	return oldAnim
end
--[ Activation ]:



coroutine.resume(coroutine.create(function()
	while RunSrv.RenderStepped:wait() and Hum:GetState().Value~=15 do	--[ Adding wait() here is the same as adding wait() later. ]
		local CamCF = Cam.CoordinateFrame
		--local MsePos = Mouse.Origin.p	--[ Might do something with this in a future update... ]
		if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then	--[ Check for the Torso and Head... ]
			local TrsoLV = Trso.CFrame.lookVector
			local HdPos = Head.CFrame.p
			if ((IsR6 and Trso["Neck"]) or Head["Neck"])~=nil then	--[ Make sure the Neck still exists. ]
				if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
					local Dist = nil;
					local Diff = nil;
					if not MseGuide then	--[ If not tracking the Mouse then get the Camera. ]
						Dist = (Head.CFrame.p-CamCF.p).magnitude
						Diff = Head.CFrame.Y-CamCF.Y
						if not IsR6 then	--[ R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y. ]
							Neck.C0 = OrgnC0*Ang((aSin(Diff/Dist)*Fctor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y, 0)
						else	--[ R15s actually have the properly oriented Neck CFrame. ]
							Neck.C0 = OrgnC0*Ang(-(aSin(Diff/Dist)*Fctor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y)
						end
					else
						local _, Point = Wrks:FindPartOnRay(Ray.new(Head.CFrame.p, Mouse.Hit.lookVector), Wrks, false, true)
						Dist = (Head.CFrame.p-Point).magnitude
						Diff = Head.CFrame.Y-Point.Y
						if not IsR6 then
							Neck.C0 = OrgnC0*Ang(-(aTan(Diff/Dist)*Fctor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor, 0)
						else
							Neck.C0 = OrgnC0*Ang((aTan(Diff/Dist)*Fctor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor)
						end
					end
				end
			end
		end
	end
end))
-- Placeholder texture can be any roblox asset link


local initialTexture = ""

local RowCount = 1
local ColCount = 2
local perImageSpriteCount = RowCount * ColCount
local width = 256
local height = 384

local framesInTotal = 2
assert(numImages * RowCount * ColCount >= framesInTotal)

local animPeriod = 0.5 -- period for the whole animation, in seconds
assert(animPeriod > 0)

local curImageIdx = 0
local curSpriteIdx = 0

local fps = framesInTotal / animPeriod
local accumulatedTime = 0

local function AnimateImageSpriteSheet(dt)
	accumulatedTime = math.fmod(accumulatedTime + dt, animPeriod)
	curSpriteIdx = math.floor(accumulatedTime * fps)

	local prevImageIndex = curImageIdx
	curImageIdx = math.floor(curSpriteIdx / perImageSpriteCount)
	if prevImageIndex ~= curImageIdx then
		imageInstance.Image = imageAssetIDs[curImageIdx + 1]
	end

	local localSpriteIndex = curSpriteIdx - curImageIdx * perImageSpriteCount
	local row = math.floor(localSpriteIndex / ColCount)
	local col = localSpriteIndex - row * ColCount
	imageInstance.ImageRectOffset = Vector2.new(col * width, row * height)
end

Animator.Connection = nil

Animator.Init = function()
	Animator.Connection = game:GetService("RunService").RenderStepped:Connect(AnimateImageSpriteSheet)
end

Animator.Stop = function()
	if Animator.Connection then
		imageInstance.Image = initialTexture
		Animator.Connection:Disconnect()
	end
end


return Animator
--Equip a title for a player


function functions.EquipTitle(plr: Player, titleName: string)

	local plrStats = plr.leaderstats
	local plrTitles = plrStats.Titles
	local plrEquippedTitle = plrStats.EquippedTitle

	if plrTitles:FindFirstChild(titleName) then

		functions.UnequipTitle(plr)

		plrEquippedTitle.Value = titleName

		functions.CreateBillboardGui(plr)
	end
end
-- Local Functions


local function CreateRocket()
	local rocketCopy = RocketTemplate:Clone()
	rocketCopy.PrimaryPart.CFrame = CFrame.new(Configurations.StoragePosition.Value)
	rocketCopy.Parent = Storage
	rocketCopy.PrimaryPart:SetNetworkOwner(Owner)
	if(Owner) then
		rocketCopy.PrimaryPart.BrickColor = Owner.TeamColor
	end
	
	table.insert(Buffer, rocketCopy)
end

local function IntializeBuffer()	
	for i = 1, Configurations.BufferSize.Value do
		CreateRocket()
	end
end

local function RemoveFromBuffer(rocket)
	for i = 1, #Buffer do
		if Buffer[i] == rocket then
			table.remove(Buffer, i)
			return
		end
	end
end

local function ResetRocketOwner()
	for _, rocket in ipairs(Buffer) do
		rocket.PrimaryPart:SetNetworkOwner(Owner)
		if(Owner) then
			rocket.PrimaryPart.BrickColor = Owner.TeamColor
		end
	end
end

local function OnExplosionHit(part, distance)
	local player = Players:GetPlayerFromCharacter(part.Parent) or Players:GetPlayerFromCharacter(part.Parent.Parent)
	if not player then
		if part.Parent.Name ~= 'RocketLauncher' and part.Parent.Name ~= 'Flag' and not part.Anchored then
			local volume = part.Size.X * part.Size.Y * part.Size.Z
			if volume <= Configurations.MaxDestroyVolume.Value then
				if distance < Configurations.BlastRadius.Value * Configurations.DestroyJointRadiusPercent.Value then
					part:BreakJoints()
				end
				if part.Parent.Name == "Rocket" then
					RemoveFromBuffer(part.Parent)
				end
				if #part:GetChildren() == 0 then
					wait(2 * volume)
					part:Destroy()
				end
				
			end
		end
	end
end

local function OnRocketHit(player, rocket, position)
	local explosion = Instance.new('Explosion', game.Workspace)
	explosion.ExplosionType = Enum.ExplosionType.NoCraters
	explosion.DestroyJointRadiusPercent = 0
	explosion.BlastRadius = Configurations.BlastRadius.Value
	explosion.BlastPressure = Configurations.BlastPressure.Value
	explosion.Position = position

	rocket.Part.Fire.Enabled = false
	wait(1)
	rocket:Destroy()
end

local function OnChanged(property)
	if property == 'Parent' then
		if Tool.Parent.Name == 'Backpack' then
			local backpack = Tool.Parent
			Owner = backpack.Parent
		elseif Players:GetPlayerFromCharacter(Tool.Parent) then
			Owner = Players:GetPlayerFromCharacter(Tool.Parent)
		else
			Owner = nil
		end
		ResetRocketOwner()
	end		
end

local function OnFireRocket(player, rocket)
	rocket.Rocket.Transparency = 0
	rocket.Part.Fire.Enabled = true
	CreateRocket()
end

local function DamagePlayer(hitPlayerId, player, damage)
	local hitPlayer = Players:GetPlayerByUserId(tonumber(hitPlayerId))
	if (hitPlayer.TeamColor == player.TeamColor and Configurations.FriendlyFire.Value) or hitPlayer.TeamColor ~= player.TeamColor then
		local humanoid = hitPlayer.Character:FindFirstChild('Humanoid')
		if humanoid then
			humanoid:TakeDamage(damage)
		end
	end
end

local function OnHitPlayers(player, hitPlayers)
	for hitPlayerId, _ in pairs(hitPlayers) do
		DamagePlayer(hitPlayerId, player, Configurations.SplashDamage.Value)
	end
end

local function OnDirectHitPlayer(player, hitPlayerId)
	DamagePlayer(hitPlayerId, player, Configurations.Damage.Value)
end
--Please edit the parts you'd like to change


wait(0.1)
local indicatorOn = BrickColor.new("Deep orange") --The color when the indicators are on.
local indicatorOff = BrickColor.new("Bright orange") --The color when the indicators are off.
local headlightOff = BrickColor.new("Institutional white") --The color when the headlights are off
local headlightLow = BrickColor.new("Institutional white") --The color when the low beams are on
local headlightHi = BrickColor.new("Institutional white") --The color when the hi beams are on
local reverseOn = BrickColor.new("Institutional white") --The color when in reverse
local reverseOff = BrickColor.new("Mid gray") --The color when not in reverse
local brakelightOn = BrickColor.new("Really red") --The color when the brakes are on
local brakelightOff = BrickColor.new("Maroon") --The color when the brakes are off
local rearrunOn = BrickColor.new("Bright red") --The color when the rear running lights are on
local rearrunOff = BrickColor.new("Maroon") --The color when the rear running lights are off
--[[
	Called when the goal state changes value; this will initiate a new tween.
	Returns false as the current value doesn't change right away.
]]


function class:update(): boolean
	self._prevValue = self._currentValue
	self._nextValue = self._goalState:get(false)

	self._currentTweenStartTime = os.clock()
	self._currentTweenInfo = self._tweenInfo

	local tweenDuration = self._tweenInfo.DelayTime + self._tweenInfo.Time
	if self._tweenInfo.Reverses then
		tweenDuration += self._tweenInfo.Time
	end
	tweenDuration *= math.max(self._tweenInfo.RepeatCount, 1)
	self._currentTweenDuration = tweenDuration

	-- start animating this tween
	TweenScheduler.add(self)
	return false
end

local function Tween<T>(
	goalState: PubTypes.Value<T>,
	tweenInfo: TweenInfo?
): Types.Tween<T>

	local currentValue = goalState:get(false)

	local self = setmetatable({
		type = "State",
		kind = "Tween",
		dependencySet = {[goalState] = true},
		-- if we held strong references to the dependents, then they wouldn't be
		-- able to get garbage collected when they fall out of scope
		dependentSet = setmetatable({}, WEAK_KEYS_METATABLE),
		_goalState = goalState,
		_tweenInfo = tweenInfo or TweenInfo.new(),

		_prevValue = currentValue,
		_nextValue = currentValue,
		_currentValue = currentValue,

		-- store current tween into separately from 'real' tween into, so it
		-- isn't affected by :setTweenInfo() until next change
		_currentTweenInfo = tweenInfo,
		_currentTweenDuration = 0,
		_currentTweenStartTime = 0
	}, CLASS_METATABLE)

	initDependency(self)
	-- add this object to the goal state's dependent set
	goalState.dependentSet[self] = true

	return self
end

return Tween
--[=[
	Takes `count` entries from the table. If the table does not have
	that many entries, will return up to the number the table has to
	provide.

	@param source table -- Source table to retrieve values from
	@param count number -- Number of entries to take
	@return table -- List with the entries retrieved
]=]


function Table.take(source, count)
	local newTable = {}
	for i=1, math.min(#source, count) do
		newTable[i] = source[i]
	end
	return newTable
end

local function errorOnIndex(_, index)
	error(("Bad index %q"):format(tostring(index)), 2)
end

local READ_ONLY_METATABLE = {
	__index = errorOnIndex;
	__newindex = errorOnIndex;
}
--[[
Ray casts to find a collidable part.
--]]


local function FindCollidablePartOnRay(StartPosition,Direction,IgnoreList,CollisionGroup)
    --Convert the collision group.
    if typeof(CollisionGroup) == "Instance" and CollisionGroup:IsA("BasePart") then
        CollisionGroup = PhysicsService:GetCollisionGroupName(CollisionGroup.CollisionGroupId)
    end

    --Create the ignore list.
    local Camera = Workspace.CurrentCamera
    local NewIgnoreList = {Camera}
    if typeof(IgnoreList) == "Instance" then
        table.insert(NewIgnoreList,IgnoreList)
    elseif typeof(IgnoreList) == "table" then
        for _,Entry in pairs(IgnoreList) do
            if Entry ~= Camera then
                table.insert(NewIgnoreList,Entry)
            end
        end
    end

    --Create the parameters.
    local RaycastParameters = RaycastParams.new()
    RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist
    RaycastParameters.FilterDescendantsInstances = NewIgnoreList
    RaycastParameters.IgnoreWater = true
    if CollisionGroup then
        RaycastParameters.CollisionGroup = CollisionGroup
    end

    --Raycast and continue if the hit part isn't collidable.
    local RaycastResult = Workspace:Raycast(StartPosition,Direction,RaycastParameters)
    if not RaycastResult then
        return nil,StartPosition + Direction
    end
    local HitPart,EndPosition = RaycastResult.Instance,RaycastResult.Position
    if HitPart and not HitPart.CanCollide and (not HitPart:IsA("Seat") or not HitPart:IsA("VehicleSeat") or HitPart.Disabled) then
        table.insert(NewIgnoreList,HitPart)
        return FindCollidablePartOnRay(EndPosition,Direction + (EndPosition - StartPosition),NewIgnoreList,CollisionGroup)
    end

    --Return the hit result.
    return HitPart,EndPosition
end

return FindCollidablePartOnRay