Pinkstack/roblox-luau-corpus-text huggingface dataset:
--[[
	~= EXAMPLE CODE =~
	return function(gui,gTable,guiData)
		local name = gTable.Name
		if name == "YesNoPrompt" then
			local new = Instance.new("ScreenGui")
			local frame = Instance.new("Frame",new)
			frame.Size = UDim2.new(0,400,0,400)
			local yes = Instance.new("TextButton",frame)
			yes.Size = UDim2.new(0.5,0,1,0)
			yes.Text = "Yes"
			local no = yes:Clone()
			no.Text = "No"
			no.Position = UDim2.new(0.5,0,0,0)
			
			local gTable,gIndex = client.UI.Register(new)
			
			local ans
			local waiting = true
			
			gTable.CustomDestroy = function()
				waiting = false
			end
			
			yes.MouseButton1Click:Connect(function()
				ans = "Yes"
				gTable:Destroy()
			end)
			
			no.MouseButton1Click:Connect(function()
				ans = "No"
				gTable:Destroy()
			end)
			
			repeat wait() until ans or not waiting  --// Wait until answer
			return ans or false
		end
	end
	
--]]



service = nil
Routine = nil
client = nil

return function(gui, guiData, gTable)
	local contents = {}
	local lerper = 0.5
	local switch = false
	local targetColor = Color3.new(math.random(),math.random(),math.random())
	local classes = {
		Frame = true;
		TextBox = true;
		TextLabel = true;
		TextButton = true;
		ImageLabel = true;
		ImageButton = true; 
		ScrollingFrame = true;
	}
	
	local function getCont(obj)
		for i,v in pairs(obj:GetChildren()) do 
			if classes[v.ClassName] then
				table.insert(contents,v)
				getCont(v)
			end
		end
	end
	
	if classes[gui.ClassName] then
		table.insert(contents,gui)
	end
	
	getCont(gui)
	
	if gTable.Name == "List" then
		gui.Drag.Main.BackgroundTransparency = 0
	end
	
	local increment = 0.001
	local max = 0.7
	local min = 0.1
	local r,g,b = 0.1,0.5,0.8
	local rt,gt,bt = true,true,true 
	local sequence = {
		Color3.fromRGB(255, 85, 88), 
		Color3.fromRGB(78, 140, 255), 
		Color3.fromRGB(78, 255, 149)
	}
	
	local function lerpToColor(color1, color2, inc, time)
		local inc = inc or 0.1
		for i = 0, 1, inc do
			for i2,v in next,contents do
				if v.Name ~= "CapeColor" and v.Name ~= "Color" then
					v.BackgroundColor3 = color1:lerp(color2, i)
					if v:IsA("ImageLabel") or v:IsA("ImageButton") then
						v.ImageColor3 = color1:lerp(color2, i)
					end
				end
			end
			wait(time/(1/inc))
		end
	end
	
	service.TrackTask("Thread: Colorize_"..tostring(gTable.Name),function()
		while ((gTable.Active and wait()) or wait(1)) and not gTable.Destroyed do
			for i,v in next,sequence do
				local one, two = sequence[i], sequence[1]
				
				if i == #sequence then
					two = sequence[1]
				else
					two = sequence[i+1]
				end
				
				lerpToColor(one, two, 0.01, 2)
			end
		end
	end)
end
-- Handle event fire


local function toggleDoor(player, door)
	local motor = rightMotor
	if door == "left" then
		motor = leftMotor
	end
	-- Check distance to the character's Torso. If too far, don't do anything
	if player.Character and player.Character:FindFirstChild("Torso") then	
		local torso = player.Character:FindFirstChild("Torso")
		local toTorso = torso.Position - cabinet.CounterTop.Position
		if toTorso.magnitude < clickDistance then
			if open then
				motor.DesiredAngle = 0
				open = false
			else
				motor.DesiredAngle = math.pi/2
				open = true
			end
		end
	end
end

for _, Part in pairs(cabinet:GetChildren()) do
	if Part:FindFirstChild("ROBLOXInteractionEvent") and (string.match(Part.Name, "Door") or string.match(Part.Name, "Handle")) then
		local event = Part:FindFirstChild("ROBLOXInteractionEvent")
		local door = "right"
		if string.match(Part.Name, "Left") then
			door = "left"
		end
		event.OnServerEvent:connect(function(player, arguments) toggleDoor(player, door) end)
	end
end
--F.updateSound = function(Sound, Pitch, Volume)
--	if Sound then
--		if Pitch then
--			Sound.Pitch = Pitch
--		end
--		if Volume then
--			Sound.Volume = Volume
--		end
--	end
--end



F.updateWindows = function(Window, Toggle)
	if script.Parent.Parent.Windows:findFirstChild(Window) then
		script.Parent.Parent.Windows:findFirstChild(Window).Value = Toggle
	end	
end

F.volumedown = function(VolDown)
	carSeat.Parent.Body.MP.Sound.Volume = carSeat.Parent.Body.MP.Sound.Volume - 1
end

F.volumeup = function(VolUp)
	carSeat.Parent.Body.MP.Sound.Volume = carSeat.Parent.Body.MP.Sound.Volume + 1
end

F.fm = function(ok)
	carSeat.Parent.Body.MP.Sound:Stop()
	carSeat.Stations.mood.Value = ok
end

F.updateSong = function(id)
	carSeat.Stations.mood.Value = 5
	carSeat.Parent.Body.MP.Sound:Stop()
	wait()
	carSeat.Parent.Body.MP.Sound.SoundId = "rbxassetid://"..id
	wait()
	carSeat.Parent.Body.MP.Sound:Play()
end

F.pauseSong = function()
	carSeat.Stations.mood.Value = 5
	carSeat.Parent.Body.MP.Sound:Stop()
end

F.updateVolume = function(Vol)
	carSeat.Parent.Body.MP.Sound.Volume = carSeat.Parent.Body.MP.Sound.Volume + Vol/5
end

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

F.FEInfo = function()
	carSeat.Parent.Body.Dash.S.G.Enabled = true
	wait(.1)
	carSeat.Parent.Body.Dash.S.G.FE.Visible = true
end

F.delete = function(plr)
	workspace[plr]:FindFirstChildOfClass("Humanoid").Jump = true
	wait(1)
	carSeat.Parent:Destroy()
end

F.shift = function(up)
	if up == true then
		carSeat.Parent.Misc.GL.SS.Motor.DesiredAngle = -.2
		wait(.3)
		carSeat.Parent.Misc.GL.SS.Motor.DesiredAngle = 0
	else
		carSeat.Parent.Misc.GL.SS.Motor.DesiredAngle = .2
		wait(.3)
		carSeat.Parent.Misc.GL.SS.Motor.DesiredAngle = 0
	end
end

F.reverse = function(yes)
	carSeat.Parent.Body.Lights.Reverse.Material = yes and "Neon" or "SmoothPlastic"
end

F.PM = function(m,p)
	carSeat.Mode.Value = m
	carSeat.PMult.Value = p
end

F.Dyn = function(h)
	carSeat.Parent.Wheels.FL.Spring.FreeLength = h
	carSeat.Parent.Wheels.FR.Spring.FreeLength = h
	carSeat.Parent.Wheels.RL.Spring.FreeLength = h
	carSeat.Parent.Wheels.RR.Spring.FreeLength = h
end

script.Parent.OnServerEvent:connect(function(Player, Func, ...)
	if F[Func] then
		F[Func](...)
	end
end)
-- Pure function returns options with all properties.


local function normalizeDiffOptions(options_: DiffOptions?): DiffOptionsNormalized
	-- ROBLOX FIXME Luau: needs a normalization fix to avoid Key 'compareKeys' is missing from '{  }' in the type 'DiffOptions | {  }'
	local options = if options_ then options_ else {} :: DiffOptions
	return Object.assign({}, OPTIONS_DEFAULT, options, {
		compareKeys = getCompareKeys(options.compareKeys),
		contextLines = getContextLines(options.contextLines),
	}) :: DiffOptionsNormalized
end

return {
	noColor = noColor,
	normalizeDiffOptions = normalizeDiffOptions,
}
--[[
	Even though Luau can catch and rethrow arbitrary objects, only string errors
	are supported by the ScriptContext.ErrorDetailed signal (the mechanism used
	to catch unhandled errors at the top level).

	This function turns an arbitrary error object into a detailed string message
	to avoid any loss of information.
]]


local function errorToString(error_: Error | Object | string | Array<any>): string
	local errorString
	if typeof(error_) == "table" then
		if (error_ :: Error).message and (error_ :: Error).stack then
			-- Adding these clear dividers helps us split this error back up
			-- into pieces later. We include one at the beginning so that the
			-- final stack frame added by rethrowing can be carved off
			errorString = DIVIDER
				.. (error_ :: Error).message
				.. DIVIDER
				.. tostring((error_ :: Error).stack)
		else
			errorString = inspect(error_)
		end
	else
		errorString = inspect(error_)
	end

	return errorString
end
--[[ D fl V Y
This is made purely from scratch. If you say I am a free-model-noob, you are obviously blind and I will pwn you (with this wand, ironically).
This is DavyDeckwalker's magic wand, which is voice activated and comes with the primary spells from the Harry Potter books by
J. K. Rowling. It is easy to use, all you have to do is say the incantation for a spell and you automatically cast that spell.
To make your own spell, follow the included instructions. Recommended for scripters only.
]]


 

local wand = script.Parent
local stick = wand.Handle
local inc = script.Name
local owner, connect



function findNearestTorso(pos, dis)
	local list = game.Workspace:children()
	local torso = nil
	local dist = dis
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= wand.Parent) then
			temp = temp2:findFirstChild("Torso")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
				end
			end
		end
	end
	return torso
end
--------------------


local Frame = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid
if char then
	humanoid = char:FindFirstChildWhichIsA("Humanoid")
else
	char = plr.CharacterAdded:Wait()
	humanoid = char:FindFirstChildWhichIsA("Humanoid")
end
local speeds = Frame:WaitForChild("Speeds")
local event = Frame:WaitForChild("Speed")
local enabled = Frame:WaitForChild("Enabled")
local tired = false
local running = false
local moving = false
--[[
	Intended for use in tests.
	Similar to await(), but instead of yielding if the promise is unresolved,
	_unwrap will throw. This indicates an assumption that a promise has
	resolved.
]]


function Promise.prototype:_unwrap()
	if self._status == Promise.Status.Started then
		error("Promise has not resolved or rejected.", 2)
	end

	local success = self._status == Promise.Status.Resolved

	return success, unpack(self._values, 1, self._valuesLength)
end

function Promise.prototype:_resolve(...)
	if self._status ~= Promise.Status.Started then
		return
	end

	-- If the resolved value was a Promise, we chain onto it!
	if Promise.is((...)) then
		-- Without this warning, arguments sometimes mysteriously disappear
		if select("#", ...) > 1 then
			local message = (
				"When returning a Promise from andThen, extra arguments are " ..
				"discarded! See:\n\n%s"
			):format(
				self._source
			)
			warn(message)
		end

		(...):andThen(
			function(...)
				self:_resolve(...)
			end,
			function(...)
				self:_reject(...)
			end
		)

		return
	end

	self._status = Promise.Status.Resolved
	self._valuesLength, self._values = pack(...)

	-- We assume that these callbacks will not throw errors.
	for _, callback in ipairs(self._queuedResolve) do
		callback(...)
	end
end

function Promise.prototype:_reject(...)
	if self._status ~= Promise.Status.Started then
		return
	end

	self._status = Promise.Status.Rejected
	self._valuesLength, self._values = pack(...)

	-- If there are any rejection handlers, call those!
	if not isEmpty(self._queuedReject) then
		-- We assume that these callbacks will not throw errors.
		for _, callback in ipairs(self._queuedReject) do
			callback(...)
		end
	else
		-- At this point, no one was able to observe the error.
		-- An error handler might still be attached if the error occurred
		-- synchronously. We'll wait one tick, and if there are still no
		-- observers, then we should put a message in the console.

		self._unhandledRejection = true
		local err = tostring((...))

		spawn(function()
			-- Someone observed the error, hooray!
			if not self._unhandledRejection then
				return
			end

			-- Build a reasonable message
			local message = ("Unhandled promise rejection:\n\n%s\n\n%s"):format(
				err,
				self._source
			)
			warn(message)
		end)
	end
end

return Promise
--Damages the humanoid.


function PlayerDamager:DamageHumanoid(DamagingPlayer,Humanoid,Damage,ToolName)
	--Check if it can be damaged.
	if not PlayerDamager:CanDamageHumanoid(DamagingPlayer,Humanoid) or not Humanoid.Parent then
		return
	end
	
	--Damage the humanoid.
	Humanoid:TakeDamage(Damage)
	
	--Create the tag.
	local CreatorTag = Instance.new("ObjectValue")
	CreatorTag.Name = "creator"
	CreatorTag.Value = DamagingPlayer
	CreatorTag.Parent = Humanoid
	Debris:AddItem(CreatorTag,3)
end

return PlayerDamager
-- Settings for the projectile's path!
-- расчёт пути


local startPoint = Vector3.new(0,5, 0)
local targetPoint = Vector3.new(0, 5, 100)
local travelTime = 2	-- время пути
local antiGravity = 1	-- противодействие гравитации 1 - горизонталь, 0,5 по дуге
-- ROBLOX deviation: rewrote this because Lua doesn't have negative lookahead
-- currently commented out as it is unused
-- local function indentAllLines(lines: string, indent: string): string
-- 	local t = string.split(lines, '\n')
-- 	for i, l in ipairs(t) do
-- 		t[i] = indent .. l
-- 	end
-- 	return table.concat(t, '\n')
-- end
--[=[
    @interface ISimulationConfig
    @within Types
    .raycastWhitelist {BasePart} -- Raycast whitelist used for collision checks.
    .feetHeight number -- Players feet height. Height goes from -2.5 to +2.5 so any point below this number is considered the players feet. The distance between middle and feetHeight is "ledge".
    .stepSize number -- How big an object we can step over?

    The config passed to the Chickynoid [Simulation] class.
]=]


export type ISimulationConfig = {
    raycastWhitelist: { BasePart },
    feetHeight: number,
    stepSize: number,
}
--[[Weight and CG]]


	Tune.Weight			= 3296		-- Total weight (in pounds)
	Tune.WeightBSize	= {			-- Size of weight brick (dimmensions in studs ; larger = more stable)
	 --[[Width]]		6		,
	 --[[Height]]		3.5		,
	 --[[Length]]		14		}
	Tune.WeightDist		= 50		-- Weight distribution (0 - on rear wheels, 100 - on front wheels, can be <0 or >100)
	Tune.CGHeight		= .8		-- Center of gravity height (studs relative to median of all wheels)
	Tune.WBVisible		= false		-- Makes the weight brick visible
	
	--Unsprung Weight
	Tune.FWheelDensity	= .1		-- Front Wheel Density
	Tune.RWheelDensity	= .1		-- Rear Wheel Density
	Tune.FWLgcyDensity	= 1			-- Front Wheel Density [PGS OFF]
	Tune.RWLgcyDensity	= 1			-- Rear Wheel Density [PGS OFF]
	
	Tune.AxleSize		= 2			-- Size of structural members (larger = more stable/carry more weight)
	Tune.AxleDensity	= .1		-- Density of structural members
--[[
	Tells whether the current test we're in should be skipped.
]]


function TestSession:shouldSkip()
	-- If our test tree had any exclusive tests, then normal tests are skipped!
	if self.hasFocusNodes then
		for i = #self.nodeStack, 1, -1 do
			local node = self.nodeStack[i]

			-- Skipped tests are still skipped
			if node.planNode.modifier == TestEnum.NodeModifier.Skip then
				return true
			end

			-- Focused tests are the only ones that aren't skipped
			if node.planNode.modifier == TestEnum.NodeModifier.Focus then
				return false
			end
		end

		return true
	else
		for i = #self.nodeStack, 1, -1 do
			local node = self.nodeStack[i]

			if node.planNode.modifier == TestEnum.NodeModifier.Skip then
				return true
			end
		end
	end

	return false
end

return TestSession
-- functions



local function Update()
	GUN_GUI.AmmoLabel.Text	= tostring(currentAmmo)
	
	if character then
		GUN_GUI.TotalLabel.Text	= tostring(ammo[currentSize].Value)
	end
end

local function HandleCharacter(newCharacter)
	if newCharacter then
		character	= nil
		
		ammo		= newCharacter:WaitForChild("Ammo")
		character	= newCharacter
	end
end
-- Script by Tonitoni. Model link: http://www.roblox.com/Max-Zoom-Distance-script-item?id=160640387
-- v.1.1 June 7th 2015



game.Players.PlayerAdded:connect(function(player)
	wait(0.5) --Players report the script didn't work. Adding this should resolve the issue.
	player.CameraMaxZoomDistance = 100000 -- Change this to change zoom distance
end)
--Camera frustum check


local last_camera_res = nil
local last_camera_fov = nil
local cam_planes = nil
function camera_util.CheckFrustum(point, rad)
	--Update camera planes if FOV or resolution changed
	local camera = workspace.CurrentCamera
	if cam_planes == nil or camera.ViewportSize ~= last_camera_res or camera.FieldOfView ~= last_camera_fov then
		--Get camera factors
		last_camera_res = camera.ViewportSize
		last_camera_fov = camera.FieldOfView

		local aspectRatio = last_camera_res.X / last_camera_res.Y
		local hFactor = math.tan(math.rad(last_camera_fov) / 2)
		local wFactor = aspectRatio * hFactor

		--Get planes
		cam_planes = {
			Vector3.new(hFactor, 0, 1).unit,
			Vector3.new(0, wFactor, 1).unit,
			Vector3.new(-hFactor, 0, 1).unit,
			Vector3.new(0, -wFactor, 1).unit,
		}
	end

	--Test against camera planes
	local cframe = camera.CFrame
	local local_pos = cframe:inverse() * point

	for _,v in pairs(cam_planes) do
		if v:Dot(local_pos) > rad then
			return false
		end
	end

	return true
end

return camera_util
--// SERVICES //--



local CoreGuiService = game:GetService('CoreGui')
local PlayersService = game:GetService('Players')
local GuiService = game:GetService('GuiService')
local UserInputService = game:GetService('UserInputService')
local StarterGui = game:GetService('StarterGui')
local STS_Settings = script.Parent.Parent.Parent.Parent:WaitForChild('STS_Settings')

local Character = game.Players.LocalPlayer.Character
if Character == nil then
	repeat
		wait()
	until (Character ~= nil)
	print('FoundCharacter')
end
local Stamina = Character:WaitForChild('Stamina')
local Sprinting = false
local StaminaReductionRate = STS_Settings:WaitForChild('StaminaDeductionAmount').Value -- Amount taken from Stamina per SprintReductionDelay
local StaminaReductionDelay = STS_Settings:WaitForChild('StaminaDeductionDelay').Value -- Time in Seconds for SprintReductionRate to be removed from stamina
local OriginalWalkSpeed = Character.Humanoid.WalkSpeed -- Get Original WalkSpeed
local SprintSpeed = STS_Settings:WaitForChild('SprintSpeed').Value
local RegenerateDelay = STS_Settings:WaitForChild('StaminaRegenerationDelay').Value
local RegenerateValue = STS_Settings:WaitForChild('StaminaRegenerationAmount').Value
--!nonstrict
-- Roblox character sound script



local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local AtomicBinding = require(script:WaitForChild("AtomicBinding"))

local function loadFlag(flag: string)
	local success, result = pcall(function()
		return UserSettings():IsUserFeatureEnabled(flag)
	end)
	return success and result
end

local SOUND_DATA : { [string]: {[string]: any}} = {
	Climbing = {
		SoundId = "rbxasset://sounds/action_footsteps_plastic.mp3",
		Looped = true,
	},
	Died = {
		SoundId = "rbxasset://sounds/uuhhh.mp3",
	},
	FreeFalling = {
		SoundId = "rbxasset://sounds/action_falling.mp3",
		Looped = true,
	},
	GettingUp = {
		SoundId = "rbxasset://sounds/action_get_up.mp3",
	},
	Jumping = {
		SoundId = "rbxasset://sounds/action_jump.mp3",
	},
	Landing = {
		SoundId = "rbxasset://sounds/action_jump_land.mp3",
	},
	Running = {
		SoundId = "rbxasset://sounds/action_footsteps_plastic.mp3",
		Looped = true,
		Pitch = 1.85,
	},
	Splash = {
		SoundId = "rbxasset://sounds/impact_water.mp3",
	},
	Swimming = {
		SoundId = "rbxasset://sounds/action_swim.mp3",
		Looped = true,
		Pitch = 1.6,
	},
}
-- ROBLOX FIXME: Can we define ClientChatModules statically in the project config


pcall(function() ChatLocalization = require((game:GetService("Chat") :: any).ClientChatModules.ChatLocalization :: any) end)
ChatLocalization = ChatLocalization or {}

if not ChatLocalization.FormatMessageToSend or not ChatLocalization.LocalizeFormattedMessage then
	function ChatLocalization:FormatMessageToSend(key,default) return default end
end
-- Add script when player is added


game.Players.PlayerAdded:connect(addScriptAtRespawn)


local MyHook = script.Parent["Chain Hook"]
local Remote = script.Parent.RemoteEvent
local Bindable = MyHook.Talker
local Coupled = script.Parent.Coupled
local Rotator = script.Parent.Rotator.Rotator

function weld(i,j)
	local weld1 = Instance.new("Weld") 
	weld1.Name = j.Name
	weld1.Part0 = i
	weld1.Part1 = j
	weld1.C1 = j.CFrame:inverse()*i.CFrame
	weld1.Parent = j
end

function SetupDecouple(chain)
	if chain.Parent then
		Coupled.Value = true
		local b
		local a
		a = chain.AncestryChanged:connect(function(_,newpar)
			if not newpar then
				Coupled.Value = false
				a:disconnect()
				b:disconnect()
			end
		end)
		b = chain.ChildRemoved:connect(function()
			Coupled.Value = false
			a:disconnect()
			b:disconnect()
			wait()
			chain:Destroy()
		end)
	end
end

Bindable.Event:connect(function(data)
	if data["Chain"] then
		SetupDecouple(data["Chain"])
	end
end)

function couple(hook1,hook2)
	if hook1.Velocity.magnitude > 0.5 or hook2.Velocity.magnitude > 0.5 then
		return false
	end
	if (hook1.Position-hook2.Position).magnitude > 5 and (hook1.Position-hook2.Position).magnitude < 3 then
		return false
	end
	local chain = Instance.new("RopeConstraint")
	chain.Attachment0 = hook1.Attachment
	chain.Attachment1 = hook2.Attachment
	chain.Color = BrickColor.new("Flint")
	chain.Thickness = 0.2
	chain.Parent = Workspace
	chain.Visible = true
	chain.Name = "Chain Link Coupler"
	chain.Length = (hook1.Position-hook2.Position.magnitude)
	script.Decouple:Clone().Parent = chain
	return true
end

Remote.OnServerEvent:connect(function(player,data)
	if data["Connect this"] and data["Connect this"].Name == "Chain Hook" and data["Connect this"] ~= MyHook and not Coupled.Value and not data["Connect this"].Parent.Coupled.Value then
		couple(MyHook,data["Connect this"])
	end
end)
-----------------------------------------------





function findAllFlagStands(root)
	local c = root:children()
	for i=1,#c do
		if (c[i].className == "Model" or c[i].className == "Part") then
			findAllFlagStands(c[i])
		end
		if (c[i].className == "FlagStand") then
			table.insert(stands, c[i])
		end
	end
end

function hookUpListeners()
	for i=1,#stands do
		stands[i].FlagCaptured:connect(onCaptureScored)
	end
end

function onPlayerEntered(newPlayer)

	if CTF_mode == true then

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"

		local captures = Instance.new("IntValue")
		captures.Name = "Captures"
		captures.Value = 0


		captures.Parent = stats

		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		stats.Parent = newPlayer

	else

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"
		local kills = false
		if Settings.LeaderboardSettings.KOs then
			kills = Instance.new("IntValue")
			kills.Name = Settings.LeaderboardSettings.KillsName
			kills.Value = 0
		end
		local deaths = false
		if Settings.LeaderboardSettings.WOs then
			deaths = Instance.new("IntValue")
			deaths.Name = Settings.LeaderboardSettings.DeathsName
			deaths.Value = 0
		end
		
		local Cash = false
		if Settings.LeaderboardSettings.ShowCurrency then
			Cash = Instance.new("StringValue")
			Cash.Name = Settings.CurrencyName
			Cash.Value = 0
		end
		
		local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(newPlayer.Name)
		if PlayerStats ~= nil then
			if Cash then
				local Short = Settings.LeaderboardSettings.ShowShortCurrency
				PlayerStats.Changed:connect(function()
					if (Short) then
						Cash.Value = Settings:ConvertShort(PlayerStats.Value)
					else
						Cash.Value = Settings:ConvertComma(PlayerStats.Value)
					end
				end)
			end
		end
		if kills then
		kills.Parent = stats
		end
		if deaths then
		deaths.Parent = stats
		end
		if Cash then
		cash.Parent = stats
		end

		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		local humanoid = newPlayer.Character.Humanoid

		humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )

		-- start to listen for new humanoid
		newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )


		stats.Parent = newPlayer

	end

end


function onCaptureScored(player)

		local ls = player:findFirstChild("leaderstats")
		if ls == nil then return end
		local caps = ls:findFirstChild("Captures")
		if caps == nil then return end
		caps.Value = caps.Value + 1

end


findAllFlagStands(game.Workspace)
hookUpListeners()
if (#stands > 0) then CTF_mode = true end
game.Players.ChildAdded:connect(onPlayerEntered)
--// Handling Settings		


	Firerate = 60 / 780; -- 60 = 1 Minute, 700 = Rounds per that 60 seconds. DO NOT TOUCH THE 60!
	
	FireMode = 2; -- 1 = Semi, 2 = Auto, 3 = Burst, 4 = Bolt Action, 5 = Shot, 6 = Explosive