Pinkstack/roblox-luau-corpus-text huggingface dataset:
--- Handles user input when the box is focused


function Window:BeginInput(input, gameProcessed)
	if GuiService.MenuIsOpen then
		self:Hide()
	end

	if gameProcessed and not self:IsVisible() then
		return
	end

	if self.Cmdr.ActivationKeys[input.KeyCode] then -- Activate the command bar
		if self.Cmdr.MashToEnable and not self.Cmdr.Enabled then
			if tick() - lastPressTime < 1 then
				if pressCount >= 5 then
					return self.Cmdr:SetEnabled(true)
				else
					pressCount = pressCount + 1
				end
			else
				pressCount = 1
			end
			lastPressTime = tick()
		elseif self.Cmdr.Enabled then
			self:SetVisible(not self:IsVisible())
			wait()
			self:SetEntryText("")

			if GuiService.MenuIsOpen then -- Special case for menu getting stuck open (roblox bug)
				self:Hide()
			end
		end

		return
	end

	if self.Cmdr.Enabled == false or not self:IsVisible() then
		if self:IsVisible() then
			self:Hide()
		end

		return
	end

	if self.Cmdr.HideOnLostFocus and table.find(MOUSE_TOUCH_ENUM, input.UserInputType) then
		local ps = input.Position
		local ap = Gui.AbsolutePosition
		local as = Gui.AbsoluteSize
		if ps.X < ap.X or ps.X > ap.X + as.X or ps.Y < ap.Y or ps.Y > ap.Y + as.Y then
			self:Hide()
		end
	elseif input.KeyCode == Enum.KeyCode.Down then -- Auto Complete Down
		self:SelectVertical(1)
	elseif input.KeyCode == Enum.KeyCode.Up then -- Auto Complete Up
		self:SelectVertical(-1)
	elseif input.KeyCode == Enum.KeyCode.Return then -- Eat new lines
		task.wait()
		self:SetEntryText(string.gsub(string.gsub(self:GetEntryText(), '\n', ''), '\r', ''))
	elseif input.KeyCode == Enum.KeyCode.Tab then -- Auto complete
		local item = self.AutoComplete:GetSelectedItem()
		local text = self:GetEntryText()
		if item and not (text:sub(#text, #text):match("%s") and self.AutoComplete.LastItem) then
			local replace = item[2]
			local newText
			local insertSpace = true
			local command = self.AutoComplete.Command

			if command then
				local lastArg = self.AutoComplete.Arg

				newText = command.Alias
				insertSpace = self.AutoComplete.NumArgs ~= #command.ArgumentDefinitions
					and self.AutoComplete.IsPartial == false

				local args = command.Arguments
				for i = 1, #args do
					local arg = args[i]
					local segments = arg.RawSegments
					if arg == lastArg then
						segments[#segments] = replace
					end

					local argText = arg.Prefix .. table.concat(segments, ",")

					-- Put auto completion options in quotation marks if they have a space
					if argText:find(" ") or argText == "" then
						argText = ("%q"):format(argText)
					end

					newText = ("%s %s"):format(newText, argText)

					if arg == lastArg then
						break
					end
				end
			else
				newText = replace
			end
			-- need to wait a frame so we can eat the \t
			wait()
			-- Update the text box
			self:SetEntryText(newText .. (insertSpace and " " or ""))
		else
			-- Still need to eat the \t even if there is no auto-complete to show
			wait()
			self:SetEntryText(self:GetEntryText())
		end
	else
		self:ClearHistoryState()
	end
end
-- WorldSize + ScreenSize -> Depth needed


function ScreenSpace.GetDepthForWidth(screenWidth, worldWidth)
	local aspectRatio = ScreenSpace.AspectRatio()
	local hfactor = math.tan(math.rad(workspace.CurrentCamera.FieldOfView)/2)
	local wfactor = aspectRatio*hfactor
	local sx, sy = ScreenSpace.ViewSizeX(), ScreenSpace.ViewSizeY()
	--
	return -(sx * worldWidth) / (screenWidth * 2 * wfactor)
end
function ScreenSpace.GetDepthForHeight(screenHeight, worldHeight)
	local hfactor = math.tan(math.rad(workspace.CurrentCamera.FieldOfView)/2)
	local sy = ScreenSpace.ViewSizeY()
	--
	return -(sy * worldHeight) / (screenHeight * 2 * hfactor)
end
-- ROBLOX TODO: continue to implement prettyFormat plugins


local prettyFormatPlugins = PrettyFormat.plugins
local PLUGINS = {
	prettyFormatPlugins.AsymmetricMatcher,
	-- ROBLOX deviation: Roblox Instance matchers
	prettyFormatPlugins.RobloxInstance,
}

type MatcherHintColor = (string) -> string -- subset of Chalk type

export type MatcherHintOptions = {
	comment: string?,
	-- ROBLOX TODO? should be MatcherHintColor like in upstream, but requires modeling Chalk differently
	expectedColor: MatcherHintColor?,
	isDirectExpectCall: boolean?,
	isNot: boolean?,
	promise: string?,
	-- ROBLOX TODO? should be MatcherHintColor like in upstream, but requires modeling Chalk differently
	receivedColor: string?,
	secondArgument: string?,
	-- ROBLOX TODO? should be MatcherHintColor like in upstream, but requires modeling Chalk differently
	secondArgumentColor: MatcherHintColor?,
}

export type DiffOptions = ImportDiffOptions

local EXPECTED_COLOR = chalk.green
local RECEIVED_COLOR = chalk.red
local INVERTED_COLOR = chalk.inverse
local BOLD_WEIGHT = chalk.bold
local DIM_COLOR = chalk.dim

local MULTILINE_REGEXP = "\n"
local SPACE_SYMBOL = utf8.char(183) -- middle dot

local NUMBERS = {
	"zero",
	"one",
	"two",
	"three",
	"four",
	"five",
	"six",
	"seven",
	"eight",
	"nine",
	"ten",
	"eleven",
	"twelve",
	"thirteen",
}

local SUGGEST_TO_CONTAIN_EQUAL =
	"Looks like you wanted to test for object/array equality with the stricter `toContain` matcher. You probably need to use `toContainEqual` instead."

local replaceTrailingSpaces, getCommonAndChangedSubstrings, isLineDiffable, shouldPrintDiff, replaceMatchedToAsymmetricMatcher, isAsymmetricMatcher
local matcherErrorMessage, matcherHint

local function stringify(object: any, maxDepth: number?): string
	-- ROBLOX deviation: Added this if logic to deal with handling nil values in Lua tables
	if object == Symbol.for_("$$nil") then
		object = nil
	end
	maxDepth = maxDepth or 10

	local MAX_LENGTH = 10000
	local result

	local ok = pcall(function()
		result = prettyFormat(object, {
			maxDepth = maxDepth,
			min = true,
			plugins = PLUGINS,
		})
	end)

	if not ok then
		result = prettyFormat(object, {
			callToJSON = false,
			maxDepth = maxDepth,
			min = true,
			plugins = PLUGINS,
		})
	end

	if #result >= MAX_LENGTH and maxDepth > 1 then
		--[[
			ROBLOX TODO: Remove the "if maxDepth" check once it can pass through
			Luau cleanly
		]]
		if maxDepth then
			return stringify(object, math.floor(maxDepth / 2))
		end
	end
	return result
end

local function highlightTrailingWhitespace(text: string): string
	return text:gsub("%s+$", function(s)
		return INVERTED_COLOR(s)
	end)
end
-- Choose current Touch control module based on settings (user, dev)
-- Returns module (possibly nil) and success code to differentiate returning nil due to error vs Scriptable


function ControlModule:SelectTouchModule()
	if not UserInputService.TouchEnabled then
		return nil, false
	end
	local touchModule = nil
	local DevMovementMode = Players.LocalPlayer.DevTouchMovementMode
	if DevMovementMode == Enum.DevTouchMovementMode.UserChoice then
		touchModule = movementEnumToModuleMap[UserGameSettings.TouchMovementMode]
	elseif DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
		return nil, true	
	else
		touchModule = movementEnumToModuleMap[DevMovementMode]
	end
	return touchModule, true
end

function ControlModule:OnRenderStepped(dt)
	if self.activeController and self.activeController.enabled and self.humanoid then
		local moveVector = self.activeController:GetMoveVector()

		local vehicleConsumedInput = false
		if self.vehicleController then
			moveVector, vehicleConsumedInput = self.vehicleController:Update(moveVector, self.activeControlModule==Gamepad)
		end

		-- User of vehicleConsumedInput is commented out to preserve legacy behavior, in case some game relies on Humanoid.MoveDirection still being set while in a VehicleSeat
		--if not vehicleConsumedInput then
			self.moveFunction(Players.LocalPlayer, moveVector, self.cameraRelative)
		--end

		self.humanoid.Jump = self.activeController:GetIsJumping() or (self.touchJumpController and self.touchJumpController:GetIsJumping())
	end
end

function ControlModule:OnHumanoidSeated(active, currentSeatPart)
	if active then
		if currentSeatPart and currentSeatPart:IsA("VehicleSeat") then
			if not self.vehicleController then
				self.vehicleController = self.vehicleController.new(CONTROL_ACTION_PRIORITY)
			end
			self.vehicleController:Enable(true, currentSeatPart)
		end
	else
		if self.vehicleController then
			self.vehicleController:Enable(false, currentSeatPart)
		end
	end
end

function ControlModule:OnCharacterAdded(char)
	self.humanoid = char:FindFirstChildOfClass("Humanoid")
	while not self.humanoid do
		char.ChildAdded:wait()
		self.humanoid = char:FindFirstChildOfClass("Humanoid")
	end

	if self.humanoidSeatedConn then
		self.humanoidSeatedConn:Disconnect()
		self.humanoidSeatedConn = nil
	end
	self.humanoidSeatedConn = self.humanoid.Seated:Connect(function(active, currentSeatPart) self:OnHumanoidSeated(active, currentSeatPart) end)
end

function ControlModule:OnCharacterRemoving(char)
	self.humanoid = nil
end
--	local throtOff = script.Parent.Values.RPM.Value > 7500 and randomability <=1 and script.Parent.Values.Throttle.Value <= _Tune.IdleThrottle/100


	local redline = script.Parent.Values.Throttle.Value > 0 and math.ceil(script.Parent.Values.RPM.Value) > _Tune.Redline-_Tune.RevBounce and script.Parent.Values.Gear.Value<#_Tune.Ratios-2
	
	if redline then
		if FE then
			handler:FireServer("Backfire2")
			wait (0.1)
		else
			car.Body.Exhaust.Backfire1.Backfire2:play()
			car.Body.Exhaust.Backfire2.Backfire2:play()
			car.Body.Exhaust.Backfire3.Backfire2:play()
			car.Body.Exhaust.Backfire4.Backfire2:play()
			car.Body.Exhaust.Backfire1.Fire.Enabled = true
			car.Body.Exhaust.Backfire2.Fire.Enabled = true
			car.Body.Exhaust.Backfire3.Fire.Enabled = true
			car.Body.Exhaust.Backfire4.Fire.Enabled = true
			car.Body.Exhaust.BFLight1.SpotLight.Enabled = true
			car.Body.Exhaust.BFLight2.SpotLight.Enabled = true
			car.Body.Exhaust.BFLight3.SpotLight.Enabled = true
			car.Body.Exhaust.BFLight4.SpotLight.Enabled = true
			wait (0.03)
			car.Body.Exhaust.Backfire1.Fire.Enabled = false
			car.Body.Exhaust.Backfire2.Fire.Enabled = false
			car.Body.Exhaust.Backfire3.Fire.Enabled = false
			car.Body.Exhaust.Backfire4.Fire.Enabled = false
			car.Body.Exhaust.BFLight1.SpotLight.Enabled = false
			car.Body.Exhaust.BFLight2.SpotLight.Enabled = false
			car.Body.Exhaust.BFLight3.SpotLight.Enabled = false
			car.Body.Exhaust.BFLight4.SpotLight.Enabled = false
			wait (0.07)
		end
	end
--[[
	Rejects the promise after `seconds` seconds.
]]


function Promise.prototype:timeout(seconds, rejectionValue)
	local traceback = debug.traceback(nil, 2)

	return Promise.race({
		Promise.delay(seconds):andThen(function()
			return Promise.reject(rejectionValue == nil and Error.new({
				kind = Error.Kind.TimedOut,
				error = "Timed out",
				context = string.format(
					"Timeout of %d seconds exceeded.\n:timeout() called at:\n\n%s",
					seconds,
					traceback
				),
			}) or rejectionValue)
		end),
		self,
	})
end
Promise.prototype.Timeout = Promise.prototype.timeout

function Promise.prototype:getStatus()
	return self._status
end
Promise.prototype.GetStatus = Promise.prototype.getStatus
--BlowerSwitch



function KeepBlowerActive()
	repeat wait()
		BlowerVal.Value = true
	until BlowerSwch.Value == false or Power.Value == false
	BlowerVal.Value = false
end

BlowerSwch.Changed:Connect(function()
	if BlowerSwch.Value == true then
		BlowerSwch.Parent.P1.Transparency = 1
		BlowerSwch.Parent.P2.Transparency = 0
		ClickSound:Play()
		if Power.Value == true then
			KeepBlowerActive()
		end
	else
		BlowerSwch.Parent.P1.Transparency = 0
		BlowerSwch.Parent.P2.Transparency = 1
		ClickSound:Play()
		BlowerVal.Value = false
	end
end)
--	if game.ReplicatedStorage.Tools:FindFirstChild(Object.Name) then


	if Object:FindFirstChild("Handle") and not Rotation then -- Soybeen added 7/29/2020
		Rotation = Vector3.new(0,90,0)
	end
	
	
	local Cam = Instance.new("Camera",Viewport)
	
	Cam.FieldOfView = 50
	
	Object = Object:Clone()
	
	Object.Parent = Viewport
	
	Cam.CameraType = Enum.CameraType.Scriptable
	
	Cam.CameraSubject = Object
	
	Viewport.CurrentCamera = Cam
	
	-- Size viewport and adjust properties.
	Viewport.Size = UDim2.new(1,0,1,0)
	
	Viewport.Position = UDim2.new(0.5,0,0.5,0)
	
	Viewport.AnchorPoint = Vector2.new(0.5,0.5)
	
	Viewport.BackgroundTransparency = 1 
	
	Viewport.BackgroundColor3 = Color3.fromRGB(0,0,0)
	
	local function GetLongestSide(VectorThree)
		local LongestSide = VectorThree.X
		
		if VectorThree.Y > LongestSide then
			LongestSide = VectorThree.Y
		end
		
		if VectorThree.Z > LongestSide then
			LongestSide = VectorThree.Z
		end
		
		return LongestSide
	end
	
	-- Position camera relative to object size average.
	if Object:IsA("BasePart") then
		local Offset = distanceOverride or GetLongestSide(Object.Size)
		
		--local avgsize = (Object.Size.X + Object.Size.Y + Object.Size.Z) / 3
		
		Object.CFrame = CFrame.new(0,0,0) * CFrame.Angles(math.rad(Rotation.X),math.rad(Rotation.Y),math.rad(Rotation.Z)) 
		
		Cam.CFrame =  CFrame.new(0,0,Offset + (1.5 * (Offset/4)))
		
		Cam.CFrame = CFrame.new(Cam.CFrame.p,Object.Position)
				
		
	elseif Object:IsA("Model") and Object.PrimaryPart then
		local Extents = Object:GetExtentsSize()
		
		local Offset = distanceOverride or GetLongestSide(Extents) --(Extents.X + Extents.Y + Extents.Z) / 3
		
		local ModelMiddlePos = Vector3.new(Extents.X/2,Extents.Y/2,Extents.Z/2)
		
		Object:SetPrimaryPartCFrame(CFrame.new(0,0,0) * CFrame.Angles(math.rad(Rotation.X),math.rad(Rotation.Y),math.rad(Rotation.Z)))
		
		if Offset/4 >= 1 then
			Cam.CFrame = CFrame.new(Object:GetModelCFrame().p) * CFrame.new(0,0,Offset + (1.5 * (Offset/4)))
		else
			Cam.CFrame = CFrame.new(Object:GetModelCFrame().p) * CFrame.new(0,0,Offset + 1.5)
		end
		
		Cam.CFrame = CFrame.new(Cam.CFrame.p,Object:GetModelCFrame().p)
	else
		Object:Destroy()
		Viewport:Destroy()
		return
	end
	
	if Viewport.Parent ~= parent then
		Viewport.Parent = parent
	end
	
	Viewport.ZIndex = parent.ZIndex
	
	if parent:IsA("ImageLabel") then
		parent.Image = ""
	end
	
	return Viewport
end


return VC
-- Stats


local stats = {
	{
		Name = "Wins",
		Type = "IntValue",
		DefaultValue = "0",
	},
}

function LeaderboardManager.new(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	for i, stat in pairs(stats) do
		local leaderstat = Instance.new(stat.Type)
		leaderstat.Name = stat.Name
		leaderstat.Value = stat.DefaultValue
		leaderstat.Parent = leaderstats
	end
end

function LeaderboardManager:getStat(player, stat)
	local leaderstats = player:FindFirstChild("leaderstats")
	if not leaderstats then return false end
	
	if leaderstats then
		return leaderstats:FindFirstChild(stat)
	end
end

function LeaderboardManager:setStat(player, stat, value)
	local stat = LeaderboardManager:getStat(player, stat)
	
	if stat then
		stat.Value = value 
	end
end

function LeaderboardManager:incrementStat(player, stat, value)
	if not value then value = 1 end
	
	local stat = LeaderboardManager:getStat(player, stat)
	
	if stat then
		stat.Value = stat.Value + value
	end
end

function LeaderboardManager:decrementStat(player, stat, value)
	if not value then value = 1 end
	
	local stat = LeaderboardManager:getStat(player, stat)
	
	if stat then
		stat.Value = stat.Value - value
	end
end

function LeaderboardManager:resetStat(player, stat)
	local stat = LeaderboardManager:getStat(player, stat)
	
	if stat then		
		for i, defaultStat in pairs(stats) do
			if stat == defaultStat.Name then
				stat.Value = defaultStat.DefaultValue	
				return
			end
		end
		
		stat.Value = 0
	end
end

function LeaderboardManager:resetStats(player)
	local leaderstats = player:FindFirstChild("CustomLeaderstats")
	if not leaderstats then return "No leaderstats found" end
		
	  for i, stat in pairs(leaderstats:GetChildren()) do
          LeaderboardManager:resetState(player, stat)
      end
end

return LeaderboardManager
-- ReplicatedStorage --


function CircleClick(Button, X, Y)
	coroutine.resume(coroutine.create(function()
		
		Button.ClipsDescendants = true
		
		local Circle = script:WaitForChild("Circle"):Clone()
			Circle.Parent = Button
			local NewX = X - Circle.AbsolutePosition.X
			local NewY = Y - Circle.AbsolutePosition.Y
			Circle.Position = UDim2.new(0, NewX, 0, NewY)
		
		local Size = 0
			if Button.AbsoluteSize.X > Button.AbsoluteSize.Y then
				 Size = Button.AbsoluteSize.X*1.5
			elseif Button.AbsoluteSize.X < Button.AbsoluteSize.Y then
				 Size = Button.AbsoluteSize.Y*1.5
			elseif Button.AbsoluteSize.X == Button.AbsoluteSize.Y then																										Size = Button.AbsoluteSize.X*1.5
			end
		
		local Time = 0.5
			Circle:TweenSizeAndPosition(UDim2.new(0, Size, 0, Size), UDim2.new(0.5, -Size/2, 0.5, -Size/2), "Out", "Quad", Time, false, nil)
			for i=1,10 do
				Circle.ImageTransparency = Circle.ImageTransparency + 0.01
				wait(Time/10)
			end
			Circle:Destroy()
			
	end))
end

return CircleClick
-- Detect input to run or crawl


UIS.InputBegan:Connect(function(input)
	-- Detect input to run
	if input.KeyCode==Enum.KeyCode.LeftShift then
		-- Make sure not crawling or running already
		if shiftDown==false and not cDown then
			-- Run
			shiftDown=true
			hum.WalkSpeed=32
		end
	-- Detect input to crawl
	else if input.KeyCode==Enum.KeyCode.C then
			-- Make sure not running or crawling already
			if cDown==false and not shiftDown then
				-- Crawl
				cDown=true
				hum.WalkSpeed=5
				--crawlAnm:Play()
			end
		end
	end
end)
--local Screen = carSeat.Parent.AudioPlayerScreen.SurfaceGui <-- soon


local Song = script.Parent.AudioPlayerGui.Song
local Audio = carSeat.Audio

vol = 5

function changeSong()
	
	local effect = carSeat.Audio.EqualizerSoundEffect
	if effect.HighGain == 5 then
		effect.HighGain = -80
		effect.MidGain = -25
		onOff.Text = "IN"
	else
		effect.HighGain = 5
		effect.MidGain = 7
		onOff.Text = "OUT"
	end
	
end

function playSong()
	
	local id = player.PlayerGui.AudioPlayer.AudioPlayerGui.TextBox.Text
	Audio:Stop()
	Audio.SoundId = "http://www.roblox.com/asset/?id="..id
	Audio:Play()
	--Screen.Song.Text = game:GetService("MarketplaceService"):GetProductInfo(id).Name
	Song.Text = game:GetService("MarketplaceService"):GetProductInfo(id).Name
	--Screen.ID.Text = id

end

function stopSong()
	
	Audio:Stop()
	
end

function volUp()

	if vol + 0.1 <= 5 then
		vol = vol + 0.1
		Audio.Volume = vol	
		player.PlayerGui.AudioPlayer.AudioPlayerGui.Vol.Text = tostring(vol*1) .. "%"
		--Screen.Vol.Text = tostring(vol*100) .. "%"
	end
	
end

function volDown()
		
	if vol - 0.1 >= 0 then
		vol = vol - 0.1
		Audio.Volume = vol
		player.PlayerGui.AudioPlayer.AudioPlayerGui.Vol.Text = tostring(vol*1) .. "%"
		--Screen.Vol.Text = tostring(vol*100) .. "%"
	end
	
end

ChangeButton.MouseButton1Click:connect(function()
	
	changeSong()
	
end)

VolUpButton.MouseButton1Click:connect(function()
	
	volUp()
	
end)

VolDownButton.MouseButton1Click:connect(function()
	
	volDown()
	
end)

PlayButton.MouseButton1Click:connect(function()
	
	playSong()
	
end)

PauseButton.MouseButton1Click:connect(function()
	
	stopSong()
	
end)
--//Suspension//--


RideHeightFront = 2.3 --{This value will increase the ride height for front}
RideHeightRear = 2.9--{This value will increase the ride height for rear}

StiffnessFront = 5 --[0-10]{HIGHER STIFFNESS DECREASES SPAWNING STABILITY}
StiffnessRear = 4 --[0-10]{This value will increase the stiffness for rear} (S/A)

AntiRollFront = 2 --[0-10]{HIGHER STIFFNESS DECREASES SPAWNING STABILITY}
AntiRollRear = 3 --[0-10]{This value will reduce roll on the rear} (S/A)

CamberFront = -0.2 --[0-10]{Camber to the front in degrees}
CamberRear = -1.3 --[0-10]{Camber to the rear in degrees}
-- ================================================================================
-- LOCAL FUNCTIONS
-- ================================================================================


local function CheckNAN(value, returnIfNan)
	return (value == value and value or returnIfNan)
end -- CheckNAN

local function DeltaAngle(current, target)
	local num = (target - current) % TAU
	if num > PI then
		num = (num - TAU)
	end
	return num
end -- DeltaAngle()

local function DeltaAngleV3(pos1, pos2)
	local x = DeltaAngle(pos1.X, pos2.X)
	local y = DeltaAngle(pos1.Y, pos2.Y)
	local z = DeltaAngle(pos1.Z, pos2.Z)
	return V3(x, y, z)
end -- DeltaAngleV3()
--	carSeat.Parent.Body.Dash.Screen.G.Radio.VOLMENU.VolumeText.Text = "VOLUME: "..carSeat.Parent.Body.MP.Sound.Volume


end

F.updateValue = function(Val, Value)
	if Val then
		Val.Value = Value
	end
end


F.FMSwitch = function(FM)
	if carSeat.Stations.mood.Value == 5 then
		carSeat.Parent.Body.MP.Sound:Stop()
		carSeat.Stations.mood.Value = 2
-- Waits for the child of the specified parent


local function WaitForChild(parent, childName)
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

local Tool = script.Parent

local Animations = {}
local MyHumanoid
local MyCharacter


local function PlayAnimation(animationName)
	if Animations[animationName] then
		Animations[animationName]:Play()
	end
end

local function StopAnimation(animationName)
	if Animations[animationName] then
		Animations[animationName]:Stop()
	end
end


function OnEquipped(mouse)
	MyCharacter = Tool.Parent
	MyHumanoid = WaitForChild(MyCharacter, 'Humanoid')
	if MyHumanoid then
		Animations['IdleAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'Idle'))
	end
	PlayAnimation('IdleAnim')
end

function OnUnequipped()
	for animName, _ in pairs(Animations) do
		StopAnimation(animName)
	end
end

Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)