Pinkstack/roblox-luau-corpus-text huggingface dataset:
-- ROBLOX deviation START: handle template data


local function maybeHandleTemplateString(table_: any): Global_EachTable
	if typeof(table_) == "string" then
		local templateString = table_ :: string
		local raw = templateString
		local strings = {}
		local expressions = {}
		local startIndex = 1
		local endIndex = 1
		local expressionStarted = false
		for i = 1, #templateString do
			local current = string.sub(templateString, i, i)
			local next = if i < #templateString then string.sub(templateString, i + 1, i + 1) else nil
			if i == #templateString then
				if expressionStarted then
					error("expression not closed")
				end
				table.insert(strings, string.sub(templateString, startIndex))
			elseif not expressionStarted and current == "$" then
				if next == "{" then
					expressionStarted = true
					endIndex = i - 1
				end
			elseif expressionStarted and current == "}" then
				local str = string.sub(templateString, startIndex, endIndex)
				local exp = string.sub(templateString, endIndex + 3, i - 1)
				table.insert(strings, str)
				table.insert(expressions, exp)
				startIndex = i + 1
				expressionStarted = false
			end
		end

		return (setmetatable(strings, {
			__index = {
				raw = raw,
			},
		}) :: any) :: Global_EachTable
	else
		return table_
	end
end
--------LEFT DOOR 9--------


game.Workspace.doorleft.l71.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l72.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l73.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l61.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l62.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l63.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l52.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l53.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l51.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l43.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l42.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l41.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l33.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l32.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l31.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l23.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l22.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l21.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l13.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l12.BrickColor = BrickColor.new(135)
game.Workspace.doorleft.l11.BrickColor = BrickColor.new(135)
--			game.Workspace.Points:ClearAllChildren()
--			local ps = path:GetPointCoordinates()
--			for _, point in pairs(ps) do
--				local part = Instance.new("Part", game.Workspace.Points)
--				part.CanCollide = false
--				part.Anchored = true
--				part.FormFactor = Enum.FormFactor.Custom
--				part.Size = Vector3.new(1,1,1)
--				part.Position = point
--			end			


			
			currentPointIndex = 1
			lastTargetPos = target
		end
		
		if path then
			local points = path:GetPointCoordinates()
			if currentPointIndex < #points then
				local currentPoint = points[currentPointIndex]
				if character:FindFirstChild("HumanoidRootPart") then
					local distance = (character.HumanoidRootPart.Position - currentPoint).magnitude
					if distance < NextPointThreshold then
						currentPointIndex = currentPointIndex + 1
					end
					
					character.Humanoid:MoveTo(points[currentPointIndex])
					if points[currentPointIndex].Y - character.HumanoidRootPart.Position.Y > JumpThreshold then
						character.Humanoid.Jump = true
					end
				end
			else
				if character:FindFirstChild("Humanoid") then
					character.Humanoid:MoveTo(target)
				end
			end
		end
	end
	
	return this
end
return PathfindingUtility
--[[
	Returns a boolean value of whether a plant fits in a pot based on the
	plant size and the pot size. These sizes are pulled from attributes
	on the plant and pot prefabs.
--]]



local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Attribute = require(ReplicatedStorage.Source.SharedConstants.Attribute)
local ItemCategory = require(ReplicatedStorage.Source.SharedConstants.ItemCategory)

local getItemByIdInCategory = require(ReplicatedStorage.Source.Utility.Farm.getItemByIdInCategory)
local getAttribute = require(ReplicatedStorage.Source.Utility.getAttribute)

local function checkSeedFitsInPot(seedId: string, potId: string)
	local seedModel = getItemByIdInCategory(seedId, ItemCategory.Seeds)
	local potModel = getItemByIdInCategory(potId, ItemCategory.Pots)

	local plantSize: number = getAttribute(seedModel, Attribute.PlantSize)
	local potSize: number = getAttribute(potModel, Attribute.MaxPlantSize)

	return plantSize <= potSize
end

return checkSeedFitsInPot
-- Depending on the player's preference, this fades away other players.
-- 
-- ForbiddenJ



RunService = game:GetService("RunService")

FullyOpaqueDistance = 32

LocalPlayer = game.Players.LocalPlayer
GhostPlayersSetting = game.ReplicatedStorage.ClientConfig.GhostPlayers

PlayerCharacters = {} -- List of character models indexed by player objects.

function RegisterPlayer(player)
	player.CharacterAdded:Connect(function(character)
		PlayerCharacters[player] = character
		if GhostPlayersSetting.Value == 2 then
			SetTransparency(character, 1)
		end
	end)
	player.CharacterRemoving:Connect(function(character)
		PlayerCharacters[player] = nil
	end)
	
	PlayerCharacters[player] = player.Character
	if player.Character ~= nil and GhostPlayersSetting.Value == 2 then
		SetTransparency(player.Character, 1)
	end
end
function SetTransparency(character, transparency)
	assert(typeof(character) == "Instance" and character:IsA("Model"), "Must provide a valid Model.")
	assert(typeof(transparency) == "number", "Must provide a valid number for transparency.")
	
	local roundedTransparency = math.ceil(transparency * 10) / 10
	
	if character ~= PlayerCharacters[LocalPlayer] then
		for i, item in ipairs(character:GetDescendants()) do
			if item:IsA("BasePart") then
				item.LocalTransparencyModifier = roundedTransparency
			end
		end
	end
end
function Update()
	if GhostPlayersSetting.Value == 1 then
		local playerTorso = PlayerCharacters[LocalPlayer] and PlayerCharacters[LocalPlayer]:FindFirstChild("HumanoidRootPart")
		local playerPosition = playerTorso ~= nil and playerTorso.Position or Vector3.new(0, 0, 0)
		
		for player, character in pairs(PlayerCharacters) do
			if player ~= LocalPlayer then
				local rootPart = character:FindFirstChild("HumanoidRootPart")
				local magnitude = rootPart ~= nil and (rootPart.Position - playerPosition).Magnitude or FullyOpaqueDistance
				local transparency = 1 - math.min(magnitude / FullyOpaqueDistance, 1)
				SetTransparency(character, transparency)
			end
		end
	end
end

for i, player in ipairs(game.Players:GetPlayers()) do
	RegisterPlayer(player)
end
game.Players.PlayerAdded:Connect(RegisterPlayer)

GhostPlayersSetting.Changed:Connect(function(value)
	if value == 0 then
		for player, character in pairs(PlayerCharacters) do
			SetTransparency(character, 0)
		end
	elseif value == 2 then
		for player, character in pairs(PlayerCharacters) do
			SetTransparency(character, 1)
		end
	end
end)
----[[ Color Settings ]]


module.BackGroundColor = Color3.new(0, 0, 0)
module.DefaultChatColor = Color3.new(1, 1, 1)
module.DefaultMessageColor = Color3.new(1, 1, 1)
module.DefaultNameColor = Color3.new(1, 1, 1)
module.ChatBarBackGroundColor = Color3.new(0, 0, 0)
module.ChatBarBoxColor = Color3.new(1, 1, 1)
module.ChatBarTextColor = Color3.new(0, 0, 0)
module.ChannelsTabUnselectedColor = Color3.new(0, 0, 0)
module.ChannelsTabSelectedColor = Color3.new(30/255, 30/255, 30/255)
module.DefaultChannelNameColor = Color3.fromRGB(35, 76, 142)
module.WhisperChannelNameColor = Color3.fromRGB(102, 14, 102)
module.ErrorMessageTextColor = Color3.fromRGB(245, 50, 50)
--[=[
	@return Shake
	Construct a new Shake instance.
]=]


function Shake.new()
	local self = setmetatable({}, Shake)
	self.Amplitude = 1
	self.Frequency = 1
	self.FadeInTime = 1
	self.FadeOutTime = 1
	self.SustainTime = 0
	self.Sustain = false
	self.PositionInfluence = Vector3.one
	self.RotationInfluence = Vector3.one
	self.TimeFunction = if RunService:IsRunning() then time else os.clock
	self._timeOffset = rng:NextNumber(-1e9, 1e9)
	self._startTime = 0
	self._trove = Trove.new()
	self._running = false
	return self
end
-- Function to bind to equip event


local function equip()
	local torso = player.Character.Torso
	
	-- Setup joint variables
	neck = torso.Neck	
	oldNeckC0 = neck.C0
	shoulder = torso:FindFirstChild("Right Shoulder")
	oldShoulderC0 = shoulder.C0
	
	-- Remember old mouse icon and update current
	oldIcon = mouse.Icon
	mouse.Icon = "http://www.roblox.com/asset/?id=79658449"
	
	-- Bind TouchMoved event if on mobile. Otherwise connect to renderstepped
	if userInputService.TouchEnabled then
		connection = userInputService.TouchMoved:connect(mobileFrame)
	else
		connection = render:connect(pcFrame)
	end
	
	-- Bind TouchStarted and TouchEnded. Used to determine if character should rotate
	-- during touch input
	userInputService.TouchStarted:connect(function(touch, processed)
		mobileShouldTrack = not processed
	end)	
	userInputService.TouchEnded:connect(function(touch, processed)
		mobileShouldTrack = false
	end)
	
	-- Fire server's equip event
	game.ReplicatedStorage.ROBLOX_PistolEquipEvent:FireServer()
	
	-- Bind event for when mouse is clicked to fire server's fire event
	mouse.Button1Down:connect(function()
		game.ReplicatedStorage.ROBLOX_PistolFireEvent:FireServer(mouse.Hit.p)
	end)
	
	-- Bind reload event to mobile button and r key
	contextActionService:BindActionToInputTypes("Reload", function() 
		game.ReplicatedStorage.ROBLOX_PistolReloadEvent:FireServer()		
	end, true, "r")
	
	-- If game uses filtering enabled then need to update server while tool is
	-- held by character.
	if workspace.FilteringEnabled then
		while connection do
			wait()
			game.ReplicatedStorage.ROBLOX_PistolUpdateEvent:FireServer(neck.C0, shoulder.C0)
		end
	end
end
--[[ By: Brutez, 2/28/2015, 1:34 AM, (UTC-08:00) Pacific Time (US & Canada) ]]

--

function onTouched(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   if player then
       game:GetService("TeleportService"):Teleport(4641921091,player)  --replace the numbers with your place id
  end
end


script.Parent.Torso.Touched:connect(onTouched)
--End of example plugin
----------------------------------------------------------------------------
--[[
--Below are some real plugins that are functional.

--As another example I have included a plugin that will change the permissions of specific commands. You can see it below.

return function(set)
--make the table that holds our new perms and what command they are for
local coms={
	{cmd='insert',perms=5};
	{cmd='m',perms=5};
	{cmd='gear',perms=5};
} --Changes insert, m, and gear to place owners only.

--These are the commandss and the new permission level, refer to the top of Example Plugin for perm levels.
-- Do note the cmd HAS to be the command thats shown in :cmds command, so if you want tornado to
-- be usable by the game owner only you would put {cmd='tornado',perms=5}; but you CAN NOT user twister instead of tornado.
 
for i=1,#set.Commands do --grab commands, for i,v in pairs for some reason does not like to work for this
	coroutine.wrap(function() --wrap it to make the process go a little faster overall
	for k,v in pairs(coms) do --grab our table with the new command perms
		if v.cmd==set.Commands[i].Cmds[1] then -- if the cmd is the same as the first cmd of the target command then...
			set.Commands[i].AdminLevel=v.perms --set its admin level to our intended one.
		end
	end
	end)()
end
end

------------------------------------------------------------------------
below is a plugin I made for an automated barista bot that allows it to get chats from
the admin script and send them to the barista bot for processing, for server to server
communication like this its recommended to use bindable events, for more information here 
is the bindable event roblox wiki link: http://wiki.roblox.com/index.php?title=Bindableevent

return function(set)
local barista
for i,v in pairs(workspace:children()) do
	if v.Name=='Jessica' and v:IsA('Model') and v:FindFirstChild('BaristaStuff') then barista=v end
end --find the barista
local backup=barista:Clone() --make a backup of the barista
	set.MakePluginEvent('Chat',function(msg,plr) --Add a new function to run on chat for the plugin
		local sendchat=barista.BaristaStuff.Event --Declare the event
		sendchat:Fire(msg,plr) --send the chat to the barista
	end)
	--lets make the reset and on/off commands
	set.MakeCommand('Reset Barista',2,set.Prefix,{'resetbarista','fixbarista'},{},0,function(plr,args)
		barista:Destroy() --destroy old barista
		barista=backup:Clone() --clone the backup
		barista.Parent=workspace --put it in workspace
		barista:MakeJoints() --make some joints
	end)
	set.MakeCommand('Turn Barista On/Off',3,set.Prefix,{'barista'},{'on/off'},1,function(plr,args)
		if args[1]=='off' then
			barista:Destroy()
		elseif args[1]=='on' then
			barista=backup:Clone()
			barista.Parent=workspace
			barista:MakeJoints()
		end
	end)--does basically the same stuff as reset.
end
--]]
-----------------------------------------ONLY EDIT THESE VALUES!!!!!-----------------------------------------
-----!Instructions!-----
--Make sure you have a part in the gun named Barrel, it is where the raycast will shoot from.--
--Just place this script into any gun and edit the values below.--
--Editting anything else will risk breaking it.--
------------------------


Damage = 17
SPS = 18 -- Shots Per Second, gives a limit of how fast the gun shoots.
Recoil = 4 -- [1-10] [1 = Minigun, 10 = Sniper]
WallShoot = false -- Shoots through walls.
GH = false -- [True = RB can't hurt RB.] [False = RB can hurt RB.]
BulletColor = "Cool yellow" -- Any Brickcolor will work.
Flash = true
--[=[
	Returns a tuple of fire, fail and complete functions which
	can be chained into the the next subscription.

	```lua
	return function(source)
		return Observable.new(function(sub)
			sub:Fire("hi")

			return source:Subscribe(sub:GetFireFailComplete())
		end)
	end
	```

	@return function
	@return function
	@return function
]=]


function Subscription:GetFireFailComplete()
	return function(...)
		self:Fire(...)
	end, function(...)
		self:Fail(...)
	end, function(...)
		self:Complete(...)
	end
end
--[[
	Returns false if the given table has any of the following:
		- a key that is neither a number or a string
		- a mix of number and string keys
		- number keys which are not exactly 1..#t
]]


return function(t)
	local containsNumberKey = false
	local containsStringKey = false
	local numberConsistency = true

	local index = 1
	for x, _ in pairs(t) do
		if type(x) == 'string' then
			containsStringKey = true
		elseif type(x) == 'number' then
			if index ~= x then
				numberConsistency = false
			end
			containsNumberKey = true
		else
			return false
		end

		if containsStringKey and containsNumberKey then
			return false
		end

		index = index + 1
	end

	if containsNumberKey then
		return numberConsistency
	end

	return true
end
--[[ Main Script ]]

--

Players = game:GetService("Players")
Workspace = game:GetService("Workspace")

Seat = script.Parent
GUI = script.GUI
Active = false
Player = nil
NewGui = nil

Seat.ChildAdded:connect(function(Child)
	if Active == false then
		if Child.Name == "SeatWeld" then
			Active = true
			Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
			if Player ~= nil then
				PlayerGui = Player:FindFirstChild("PlayerGui")
				if PlayerGui ~= nil then
					NewGui = GUI:Clone()
					NewGui.Parent = PlayerGui
				end
			end
		end
	end
end)

Seat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		if Active == true then
			Active = false
			pcall(function() NewGui:Destroy() end)
			Player = nil
			NewGui = nil
		end
	end
end)
-- Remote variables


local RemoteFolder = script.Parent.Parent:WaitForChild("RemoteEvents")
local TiltRemote = RemoteFolder:WaitForChild("TiltRemote")
local PlaySound = RemoteFolder:WaitForChild("PlaySound")
local StopSound = RemoteFolder:WaitForChild("StopSound")
local ChangeSound = RemoteFolder:WaitForChild("ChangeSound")
local AnchorSegway = RemoteFolder:WaitForChild("AnchorSegway")
local UndoTags = RemoteFolder:WaitForChild("UndoTags")
local UndoHasWelded = RemoteFolder:WaitForChild("UndoHasWelded")
local DeleteWelds = RemoteFolder:WaitForChild("DeleteWelds")
local ConfigHumanoid = RemoteFolder:WaitForChild("ConfigHumanoid")
local ConfigLights = RemoteFolder:WaitForChild("ConfigLights")
--inputS.TouchEnded:Connect(function(object)
--	if object == Enum.KeyCode.DPadUp or seat.Throttle == 0 or seat.Throttle == -1 then
--		w=false
--	elseif object == Enum.KeyCode.DPadLeft or seat.Steer == 0 or seat.Steer == 1 then
--		a=false
--	elseif object == Enum.KeyCode.DPadDown or seat.Throttle == 0 or seat.Throttle == 1 then
--		s=false	
--	elseif object == Enum.KeyCode.DPadRight or seat.Steer == 0 or seat.Steer == -1 then
--		d=false		
--	end
--end)



mouse.Move:connect(function() 
	if not engine:FindFirstChild("BodyGyro") then
		local gyro=engine.BodyGyro
		gyro.cframe = mouse.Hit
	end
end)

mouse.Button1Down:Connect(function()
	firing:FireServer(true,mouse.Hit,mouse.Target)
end)

mouse.Button1Up:Connect(function()
	firing:FireServer(false,mouse.Hit,mouse.Target)
end)

function rotorSpd(spd)
	rotor1.TopParamA=-spd
	rotor1.TopParamB=spd
	rotor2.BottomParamA=-spd
	rotor2.BottomParamB=spd
end

local chg=Vector3.new(0,0,0)
local rot=0
local inc=0
while wait(.1) do
	local lv=engine.CFrame.lookVector
	local Vector = ControlModule:GetMoveVector()
--// All global vars will be wiped/replaced except script
--// All guis are autonamed client.Variables.CodeName..gui.Name



return function(data)
	local gui = script.Parent.Parent
	local bar = gui.TextLabel
	local playergui = service.PlayerGui
	
	--[[
	local TopbarMatchAdmin = client.GetReturn("Setting","TopbarMatchAdmin")
	local TopbarColor = client.GetReturn("Setting","TopbarColor")
	local TopbarTransparency = client.GetReturn("Setting","TopbarTransparency")
	local TopbarText = client.GetReturn("Setting","TopbarText")
	
	if not TopbarMatchAdmin then
		local text=TopbarText
		if text=="%TIME" then
			cPcall(function()
				repeat
					local t4=GetTime()
					local nt4
					local hour=t4:match("%d+")
					if tonumber(hour)>12 or tonumber(hour)<1 then
						nt4=math.abs(tonumber(hour)-12)..t4:match(":%d+").." PM"
					else
						nt4=t4.." AM"
					end
					bar.Text=t4.." / "..nt4
				until not wait(1)
			end)
		else
			bar.Text=TopbarText
		end
		bar.BackgroundColor3=TopbarColor
		bar.BorderSizePixel=0
		bar.BackgroundTransparency=TopbarTransparency
	end
	--]]
	
	--bar.Position=UDim2.new(0,0,0,-35)
	gTable:Ready()
end
-- theObj : (variant) the table with values to print


return function(theObj)
	local function printAll(t, spaceIndex)
		if not spaceIndex then
			spaceIndex = 0
		elseif spaceIndex > 10 then
			return "... tree too deep ..."
		end
		local spacer = string.rep("  ", spaceIndex)

		local outStr
		if not t then
			outStr = "nil"
		elseif type(t) == "table" then
			local parts = {}
			table.insert(parts, "{")
			for k, v in pairs(t) do
				local substr = string.format("%s%s : %s", spacer, tostring(k), printAll(v, spaceIndex + 1))
				table.insert(parts, substr)
			end
			table.insert(parts, string.format("%s}", spacer))
			outStr = table.concat(parts, "\n")
		else
			outStr = string.format("<%s> - %s", type(t), tostring(t))
		end

		return string.format("%s", outStr)
	end

	local outString = table.concat({
		" ********************************* ",
		printAll(theObj),
		" ********************************* "
	}, "\n")
	return outString
end
----------------------------------------------------------------------------------------------------
--------------------=[ CFRAME ]=--------------------------------------------------------------------
----------------------------------------------------------------------------------------------------


	,EnableHolster = false
	,HolsterTo = 'Torso'				 -- Put the name of the body part you wanna holster to
	,HolsterPos = CFrame.new(0,0,0) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))
	
	,RightArmPos = CFrame.new(-0.85, 0.15, -1.2) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0))	--Server
	,LeftArmPos = CFrame.new(1.05,0.9,-1.4) * CFrame.Angles(math.rad(-100),math.rad(25),math.rad(-20))	--server
	
	,ServerGunPos = CFrame.new(-.3, -1, -0.4) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0))
	,GunPos = CFrame.new(0.15, -0.15, 1) * CFrame.Angles(math.rad(90), math.rad(0), math.rad(0))

	,RightPos = CFrame.new(-.65, -0.2, -.9) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(0))	--Client
	,LeftPos = CFrame.new(1,-0.05,-1.4) * CFrame.Angles(math.rad(-120),math.rad(35),math.rad(-20))	--Client
}

return Config
--------


SYNC_RATE:Connect(function()
	for Index, Object in ipairs(ActiveHitboxes) do
		if Object.deleted then
			Handler:remove(Object.object)
		else
			for _, Point in ipairs(Object.points) do
				if not Object.active then
					Point.LastPosition = nil
				else
					local rayStart, rayDir, RelativePointToWorld = Point.solver:solve(Point, Object.debugMode)
					local raycastResult = workspace:Raycast(rayStart, rayDir, Object.raycastParams)
					Point.solver:lastPosition(Point, RelativePointToWorld)

					if raycastResult then
						local hitPart = raycastResult.Instance
						local findModel = not Object.partMode and hitPart:FindFirstAncestorOfClass("Model")
						local humanoid = findModel and findModel:FindFirstChildOfClass("Humanoid")
						local target = humanoid or (Object.partMode and hitPart)

						if target and not Object.targetsHit[target] then
							Object.targetsHit[target] = true
							Object.OnHit:Fire(hitPart, humanoid, raycastResult, Point.group)
						end
					end
					
					if Object.endTime > 0 then
						if Object.endTime <= clock() then
							Object.endTime = 0
							Object:HitStop()
						end
					end
					
					Object.OnUpdate:Fire(Point.LastPosition)
				end
			end
		end
	end
end)

return Handler
--[[Brakes]]


	Tune.ABSEnabled		= true		-- Implements ABS
	Tune.ABSThreshold	= 10		-- Slip speed allowed before ABS starts working (in SPS) 

	Tune.FBrakeForce	= 2500		-- Front brake force
	Tune.RBrakeForce	= 2000		-- Rear brake force
	Tune.PBrakeForce	= 5000		-- Handbrake force
	
	Tune.FLgcyBForce	= 15000		-- Front brake force [PGS OFF]
	Tune.RLgcyBForce	= 10000		-- Rear brake force [PGS OFF]
	Tune.LgcyPBForce	= 25000		-- Handbrake force [PGS OFF]
--[[
		___      _______                _     
	   / _ |____/ ___/ /  ___ ____ ___ (_)__ 
	  / __ /___/ /__/ _ \/ _ `(_-<(_-</ (_-<
	 /_/ |_|   \___/_//_/\_,_/___/___/_/___/
 						SecondLogic @ Inspare
]]


local FE = workspace.FilteringEnabled
local car = script.Parent.Car.Value
local handler = car:WaitForChild("AC6_FE_Sounds")
local _Tune = require(car["A-Chassis Tune"])
local on = 0
local throt=0
local redline=0

script:WaitForChild("Rev")


for i,v in pairs(car.DriveSeat:GetChildren()) do
	for _,a in pairs(script:GetChildren()) do
		if v.Name==a.Name then v:Stop() wait() v:Destroy() end
	end
end

handler:FireServer("newSound","Rev",car.DriveSeat,script.Rev.SoundId,0,script.Rev.Volume,true)
handler:FireServer("playSound","Rev")
car.DriveSeat:WaitForChild("Rev")

while wait() do
	local _RPM = script.Parent.Values.RPM.Value
	
	if script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle/100 then
		throt = math.max(.3,throt-.2)	
	else
		throt = math.min(1,throt+.1)	
	end	
	if script.Parent.Values.RPM.Value > _Tune.Redline-_Tune.RevBounce/4 and script.Parent.Values.Throttle.Value > _Tune.IdleThrottle/100 then
		redline=.5
	else
		redline=1
	end
	if not script.Parent.IsOn.Value then on=math.max(on-.015,0) else on=1 end
	local Pitch = math.max((((script.Rev.SetPitch.Value + script.Rev.SetRev.Value*_RPM/_Tune.Redline))*on^2),script.Rev.SetPitch.Value)
	handler:FireServer("updateSound","Rev",script.Rev.SoundId,Pitch,script.Rev.Volume)
end