Is this optimized? I want your oppinion!

Here is my script

local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local StarterGui = game:GetService('StarterGui')
local UserInputService = game:GetService('UserInputService')

-- disable our core gui
repeat
local Success, Error = pcall(function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
end)
wait()
until Success


--[!] const

-- max tool slot size
local TOOL_MAX_SLOTS = 10

-- i.e. GUI-related tool slot settings
local TOOL_SIZE = 50            -- tool icon size
local TOOL_BORDER_OFFSET = 15   -- gap between icons
local TOOL_BOTTOM_OFFSET = 20   -- offset from bottom of screen

-- keycode values, see here: https://create.roblox.com/docs/reference/engine/enums/KeyCode
--
--    where:
--      48 = Zero
--      49 = One
--       n = ...
--      57 = Nine
--
local NUMERIC_KEYCODE_ZRO = 48
local NUMERIC_KEYCODE_MIN = 49
local NUMERIC_KEYCODE_MAX = 57

-- i.e. the range of Enum.KeyCode[name].Value that represents numeric keycodes
local NUMERIC_KEYCODE_RANGE = NumberRange.new(NUMERIC_KEYCODE_MIN, NUMERIC_KEYCODE_MAX)

-- i.e. set up a dictionary that maps the value to a specific keycode
local KEYCODE_VALUES = { }
for _, keycode in next, Enum.KeyCode:GetEnumItems() do
	KEYCODE_VALUES[keycode.Value] = keycode
end


--[!] utils

-- checks whether a character is alive, and has valid character instances e.g. humanoid + rootpart
local function tryGetCharacterInstances(character)
	if typeof(character) ~= 'Instance' or not character:IsA('Model') or not character:IsDescendantOf(workspace) then
		return false
	end

	local humanoid = character:FindFirstChildOfClass('Humanoid')
	local humanoidState = humanoid and humanoid:GetState() or Enum.HumanoidStateType.Dead
	local humanoidRootPart = humanoid and humanoid.RootPart or nil
	if humanoidState == Enum.HumanoidStateType.Dead or not humanoidRootPart then
		return false
	end

	return true, humanoid, humanoidRootPart
end

-- wait until we find a valid character
local function awaitCharacter(player)
	if typeof(player) ~= 'Instance' or not player:IsA('Player') then
		return nil
	end

	local character
	while not character do
		if not player or not player:IsDescendantOf(Players) then
			break
		end

		local char = player.Character
		if not char then
			player.CharacterAdded:Wait()
			continue
		end

		local valid = tryGetCharacterInstances(char)
		if not valid then
			RunService.Stepped:Wait()
			continue
		end

		character = char
	end

	return character
end


--[!] methods
local function createToolSlot(parent, index, keyCode)
	local position = index - math.ceil(TOOL_MAX_SLOTS*0.5)
	local frame = Instance.new('ImageButton')
	frame.Name = 'Toolslot' .. index
	frame.Size = UDim2.fromOffset(TOOL_SIZE, TOOL_SIZE)
	frame.Position = UDim2.new(0.5, position*(TOOL_SIZE + TOOL_BORDER_OFFSET*0.5), 1, -TOOL_BOTTOM_OFFSET)
	frame.AnchorPoint = Vector2.new(0.5, 1)
	frame.BorderSizePixel = 1
	frame.BackgroundTransparency = 0
	frame.Image = ''
	frame.ImageTransparency = 1

	local posLabel = Instance.new('TextLabel')
	posLabel.Name = 'PositionLabel'
	posLabel.Size = UDim2.fromOffset(13, 13)
	posLabel.Position = UDim2.fromScale(0, 0)
	posLabel.AnchorPoint = Vector2.new(0, 0)
	posLabel.BorderSizePixel = 1
	posLabel.BackgroundTransparency = 1
	posLabel.Text = tostring(index)
	posLabel.Parent = frame
	
	local StackLabel = Instance.new('TextLabel')
	StackLabel.Name = 'StackLabel'
	StackLabel.Size = UDim2.fromOffset(13, 13)
	StackLabel.Position = UDim2.fromScale(0.8, 0.8)
	StackLabel.AnchorPoint = Vector2.new(0, 0)
	StackLabel.BorderSizePixel = 1
	StackLabel.BackgroundTransparency = 1
	StackLabel.Transparency = 1
	StackLabel.Text = 0
	StackLabel.Parent = frame

	local toolLabel = Instance.new('TextLabel')
	toolLabel.Name = 'ToolLabel'
	toolLabel.Size = UDim2.new(1, 0, 0, 25)
	toolLabel.Position = UDim2.fromScale(0.5, 0.5)
	toolLabel.AnchorPoint = Vector2.new(0.5, 0.5)
	toolLabel.BorderSizePixel = 1
	toolLabel.TextColor3 = Color3.fromHSV(0.98, 0.7, 0.75)
	toolLabel.BackgroundTransparency = 1
	toolLabel.Text = ''
	toolLabel.Parent = frame
	toolLabel.TextScaled = true

	frame.Parent = parent
	return frame, toolLabel
end


-- used to check whether the tool is still within the
-- player's backpack / their character; and if not, will remove
-- it from the slots e.g. in cases where they pressed backspace to drop the tool
--
local function handleToolRemoval(player, toolSlots, object, connection)
	-- make sure we've not just equipped the tool
	local character = player.Character
	if object:IsDescendantOf(player) or (character and object:IsDescendantOf(character)) then
		return
	end

	-- find the tool slot so we can remove it
	local toolSlot
	for i = 1, TOOL_MAX_SLOTS, 1 do
		local slot = toolSlots[i]
		if slot.Tool == object then
			toolSlot = slot
			break
		end
	end
	-- stop listening to this tool's ancestry since it's been not related to our player now
	if connection and connection.Connected then
		connection:Disconnect()
	end
end
local function RemoveToolSlot(toolSlot)
	if toolSlot then
		toolSlot.Tool = nil
		toolSlot.Label.Text = ''
	end
end

-- used to add the tool to the next best slot
-- if not already present
--
local function handleToolAdded(player, toolSlots, object, FromCharacter)
	if not object:IsA('Tool') then
		return
	end
	-- make sure we don't already exist
	-- otherwise select next best empty slot
	local CreateNewSlot = true
	local NewItem = object.NewItem
	if FromCharacter == true then
		if NewItem.Value == true then
			NewItem.Value = false
	for i,item in pairs(Players.LocalPlayer.Character:GetChildren()) do
		if item:IsA("Tool") then
			for i, S in pairs(script.Parent:GetChildren()) do
				if S:IsA("ImageButton") then
					if S.ToolLabel.Text == item.Name then
						S.StackLabel.Transparency = true
						if S.StackLabel.Text == "0" then
							S.StackLabel.Text = tonumber(S.StackLabel.Text) + 2
							CreateNewSlot = false
						else
									S.StackLabel.Text = tonumber(S.StackLabel.Text) + 1
									CreateNewSlot = false
						end
					else
					end
				end
			end
		end
	end
		if CreateNewSlot == true then
			local bestSlot
			for i = 1, TOOL_MAX_SLOTS, 1 do
				local slot = toolSlots[i]
				if slot.Tool == object then
					return
				elseif not bestSlot and not slot.Tool then
					bestSlot = i
				end
			end
			if bestSlot then
				-- i.e. we're a new tool
				bestSlot = toolSlots[bestSlot]
				bestSlot.Tool = object
				bestSlot.Label.Text = object.Name
			end
		end
		end
		end
		-- watch the ancestry of the object (i.e. it's parent)
		-- to check when the player removes the tool from its backpack
		-- and/or its character
		local watchdog
		watchdog = object.AncestryChanged:Connect(function ()
			handleToolRemoval(player, toolSlots, object, watchdog)
		end)
		end


--[!] setup
local player = Players.LocalPlayer
local backpack = player:WaitForChild('Backpack')
local character = awaitCharacter(player)
local screenGui = script.Parent


-- states
local toolSlots = table.create(TOOL_MAX_SLOTS)  -- i.e. all of the tool slots
local toolSlotMap = { }                         -- i.e. a map between a keycode and a tool slot

local selectedToolSlot                          -- the tool slot we're trying to swap
local isChangingKeybinds = false                -- whether we're trying to change our keybinds


-- set up our keybind slots
for i = 1, TOOL_MAX_SLOTS, 1 do
	-- get the KeyCode from the slot number
	local keyCode
	if i == TOOL_MAX_SLOTS then
		keyCode = KEYCODE_VALUES[NUMERIC_KEYCODE_ZRO]
	else
		keyCode = KEYCODE_VALUES[NUMERIC_KEYCODE_MIN + (i - 1)]
	end

	-- set up the slot
	local slot, toolLabel = createToolSlot(screenGui, i, keyCode)
	-- append to our list
	toolSlots[i] = {
		Tool = nil,
		Slot = slot,
		Label = toolLabel,
		ScreenGui = screenGui,
		Index = i,
		KeyCode = keyCode,
	}
	toolSlotMap[keyCode] = i

	-- set up the listener
	slot.MouseButton1Click:Connect(function ()
		-- set the selected one to our current slot
		-- if we aren't already trying to change it
		if not isChangingKeybinds then
			isChangingKeybinds = true
			selectedToolSlot = i
			return
		end

		local StackLabels = {screenGui.Toolslot1.StackLabel, screenGui.Toolslot2.StackLabel, screenGui.Toolslot3.StackLabel, screenGui.Toolslot4.StackLabel,screenGui.Toolslot5.StackLabel,
			screenGui.Toolslot6.StackLabel, screenGui.Toolslot7.StackLabel, screenGui.Toolslot8.StackLabel,screenGui.Toolslot9.StackLabel, screenGui.Toolslot10.StackLabel}
		-- swap our slots around
		local swapSlot = toolSlots[selectedToolSlot]
		local thisSlot = toolSlots[i]

		-- swap our tool reference around
		thisSlot.Tool, swapSlot.Tool = swapSlot.Tool, thisSlot.Tool

		-- swap the label text around
		thisSlot.Label.Text, swapSlot.Label.Text = swapSlot.Label.Text, thisSlot.Label.Text
		
		-- swap the transparency around
		StackLabels[i].Transparency, StackLabels[selectedToolSlot].Transparency = StackLabels[selectedToolSlot].Transparency, StackLabels[i].Transparency
		
		-- swap the stack nums around
		StackLabels[i].Text, StackLabels[selectedToolSlot].Text = StackLabels[selectedToolSlot].Text, StackLabels[i].Text
		isChangingKeybinds, selectedToolSlot = false, nil
	end)
end


-- set up our input action(s)
UserInputService.InputBegan:Connect(function (input, gameProcessed)
	-- ignore if not keyboard input and/or it's used by something else e.g. a textbox
	local inputType = input.UserInputType
	if gameProcessed or inputType ~= Enum.UserInputType.Keyboard then
		return
	end

	-- ignore if we're dead
	local isValid, humanoid = tryGetCharacterInstances(character)
	if not isValid then
		return
	end
	-- try to get the slot from the keycode and ignore if it doesn't exist
	local keyCode = input.KeyCode
	local slotIndex = toolSlotMap[keyCode]
	local toolSlot = slotIndex and toolSlots[slotIndex] or nil
	if keyCode == Enum.KeyCode.Q then
		for i, Item in pairs(Players.LocalPlayer.Character:GetChildren()) do
			if Item:IsA("Tool") then
				for i, ItemSlot in pairs(script.Parent:GetChildren()) do
					if ItemSlot:IsA("ImageButton") then
						if ItemSlot.ToolLabel.Text == Item.Name then
							if tonumber(ItemSlot.StackLabel.Text) == 0 then
								print(tonumber(ItemSlot.StackLabel.Text))
								print("deeds")
								ItemSlot.StackLabel.Text = 0
								for i, Item in pairs(Players.LocalPlayer.Character:GetChildren() and Players.LocalPlayer.Backpack:GetChildren()) do
									if Item:IsA("Tool") then
										if Item.Name == ItemSlot.ToolLabel.Text then
											toolSlots[tonumber(ItemSlot.PositionLabel.Text)].Label.Text = ""
											toolSlots[tonumber(ItemSlot.PositionLabel.Text)].Tool = nil
											Item:Destroy()
											humanoid:UnequipTools()
										end
									end
								end
							elseif tonumber(ItemSlot.StackLabel.Text) == 2 then
								print("2")
								ItemSlot.StackLabel.Text = 0
								ItemSlot.StackLabel.Transparency = 1
							elseif tonumber(ItemSlot.StackLabel.Text) >= 2 then
								ItemSlot.StackLabel.Text = tonumber(ItemSlot.StackLabel.Text) - 1
							end
						end
					end
				end
			end
		end
	end
	if not toolSlot then
		return
	end

	-- if we haven't got a tool for this slot we can ignore it
	local tool = toolSlot.Tool
	if not tool then
		return
	end

	-- equip it if we're not using it;
	-- otherwise unequip it
	if tool.Parent ~= character then
		humanoid:EquipTool(tool)
	else
		humanoid:UnequipTools()
	end
end)


-- set up our listener(s)
--    - we need to make sure we look at those already
--      in the backback too
--
--    - we also need to make sure any tools added to the char
--      via pickup get added
--
for _, object in next, backpack:GetChildren() do
	handleToolAdded(player, toolSlots, object)
end

backpack.ChildAdded:Connect(function (object)
	handleToolAdded(player, toolSlots, object, false)
end)
character.ChildAdded:Connect(function (object)
	handleToolAdded(player, toolSlots, object, true)
end)

Ive took a little bit to work on simplifying and learning tables here is my script from 2 weeks ago

2 Likes
local datastoreservice = game:GetService("DataStoreService") -- Gets Data Store Service
local MarketplaceService = game:GetService("MarketplaceService") -- Gets MarketPlaceService
local BallsStore = datastoreservice:GetDataStore("Balls.") -- Creates a data stpre
game.Players.PlayerAdded:Connect(function(Player) -- Detects When A Player Enters The Game
	Player.CharacterAppearanceLoaded:Connect(function(character) -- Detects When A Players Appearence Loads
		for i , v in pairs(character:GetDescendants()) do -- Goes Through All Of The Players Character
			if v:IsA("BasePart") or v:IsA("UnionOperation") or v:IsA("MeshPart") then -- Checks If Its A Part That Casts Shadow
				v.CastShadow = false -- Disables Cast Shadow
			end -- This Statement Went Through All Of A Characters Desendence Casting Shadows And Disables All Their Shadows
		end -- This Statement Got All Of The Decendents Of The Player
	end) -- This Function Disables A Players Shadow
	local leaderstats = Instance.new("Folder") -- Creates A Folder Named leaderstats 
	leaderstats.Name = "leaderstats" -- Names The Folder leaderstats
	leaderstats.Parent = Player	-- Puts The Folder Inside The Player
	local BowledBalls = Instance.new("IntValue") -- Creates A Value Named Bowled Balls
	BowledBalls.Parent = leaderstats -- Sets The Values Parent To leaderstats
	BowledBalls.Name = "Bowled" -- names the value "Bowled"
	local Score = Instance.new("IntValue") -- Creates A Value Named Score
	Score.Parent = leaderstats -- Sets The Values Parent To leaderstats
	Score.Name = "Score" -- Names The Value Score
	local data -- Sets A Variable Named data
	local success, errormessage = pcall(function() -- Tries To Get The Data From Roblox"s Servers
		data = BallsStore:GetAsync(Player.UserId.."-Bowled") -- Gets The Data And Sets It To The Data Value
	end) -- Ends The Function

	if success then -- Checks If It Worked
		BowledBalls.Value = data -- Sets The BowledBalls Value To The Data Value
		if data == nil then -- If The Player Has Never Played it fires this
			BowledBalls.Value = 0 -- Sets The Value To 0
		end -- This Made Sure the value was not nil
	end -- This Made Sure The Data Loaded Properly
	local success, errormessage = pcall(function() -- Tries To Get Data From Roblox"s Servers
		data = BallsStore:GetAsync(Player.UserId.."-Score") -- Gets The Data And Sets It To The Data Vale
	end) -- Ends The Function

	if success then -- Checks If it worked
		Score.Value = data -- Sets The Score Value To The Data Value
		if data == nil then -- If the player has never Played it fires this
			Score.Value = 0 -- Sets The Value to 0
		end -- This Made Sure The Score Value Is Not Nil
	end -- This Made Sure The Data Loaded Properly
end) -- This Has Disabled Players CastShadow, Created A Folder Named leaderstats, And Created 2 Values Named Bowled And Score, Then Loaded The Data Of Them
game.Players.PlayerRemoving:Connect(function(Plr) -- When The Player Leaves It Fires This
	local success, errormessage = pcall(function() -- Tries To Save The Data To Roblox's Servers
		BallsStore:SetAsync(Plr.UserId.."-Bowled", Plr.leaderstats.Bowled.Value) -- Saves The Bowled Value
	end) -- Ends The Function Saving The Bowled Value
	local success, errormessage = pcall(function() -- Tries To Save The Data To Roblox's Servers
		BallsStore:SetAsync(Plr.UserId.."-Score", Plr.leaderstats.Score.Value) -- Saved The Score Value
	end) -- Ends The Function Saving The Score Value
end) -- Saves The Data When The Player Leaves
local BadgeService = game:GetService("BadgeService") -- Gets The Badge Service -- Disclamer These Badges Dont Give Cuz I Havent Actualy Made The Badge If You Implement Your Own Badge Id It Will Work
local PlaceHolderBadge1 = 1 -- Lets A Player Set a 1st Placeholder Badge Id
local PlaceHolderBadge2 = 2 -- Lets A Player Set a 2nd Placeholder Badge Id
local PlaceHolderBadge3 = 3 -- Lets A Player Set a 3rd Placeholder Badge Id
local PlaceHolderBadge4 = 4 -- Lets A Player Set a 4th Placeholder Badge Id
local PlaceHolderBadge5 = 5 -- Lets A Player Set a 5th Placeholder Badge Id
game.ReplicatedStorage.BowlingActive.OnServerEvent:Connect(function(Player,power,Spin) -- Fires When The Fills Out The The Fourm
	local Spin = Spin * 2 -- Makes The Spin Value Bigger
	local Power = power * 2 -- Makes The Power Value Bigger
	if Player.leaderstats.Bowled.Value <= 5 then -- Checks If The Player Has A Amount Bowled To Give The Player A Ball1
		local Ball = game.ServerStorage.Ball1:Clone() -- Clones Ball1
		Ball.Parent = game.Workspace.ActiveBalls -- Sets The Cloned Balls parent To Active Balls(A Folder in workspace)
		Ball.Position = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector + Vector3.new(0,-3,0) -- Sets The Balls Position Slightly Infront Of The Player On The Ground
		Ball.Velocity = Player.Character.PrimaryPart.CFrame.LookVector * Power + Vector3.new(0,0,0) -- Sets The Balls Vellocity To What The Player Sets It To
		Ball.AssemblyAngularVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Vector3.new(Spin,0,Spin) -- Puts Spin On The Ball
		local hasPass = false -- Makes A Value Named hasPass
		local passID = 804124589 -- Sets The PassId
		local Bowled = 1 -- Sets A Bowled Value
		local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
		end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
		if hasPass == true then -- Checks If The Player Has The Pass
		Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- This Doubled The Player The Bowled Value If They Got The Pass
		if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
		Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- Doubled The bowled If The Player Has Premium
		if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- If The Player Is In My Group It Multiplys
		Player.leaderstats.Bowled.Value = Player.leaderstats.Bowled.Value + Bowled -- Adds To The Bowled Value
		Ball.Touched:Connect(function(toutcher)  -- Finds What This New Ball Toutches
			if toutcher.Name == "Pin" then -- Checks If The Pin Is Touched Then It Plays This
				toutcher.CanTouch = false -- Disables The Pins Can Toutch
				local hasPass = false -- Makes A Value Named hasPass
				local passID = 803810936 -- Sets The PassId
				local Score = 10 -- Sets A Score Value
				local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
					hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
				end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
				local children = game.Players:GetChildren() -- Gets All The Players
				if hasPass == true then -- If The Player Has The Pass It Rewards The Player This
					Score = Score * 2 -- Multiplys The Score
				end -- Awards The Playe Score Pased On If They Had The pass Or Not
				if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
					Score = Score * 2 -- Multiplys The Score Value
				end -- Doubled The bowled If The Player Has Premium
				if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
					Score = Score * 2 -- Multiplys The Score Value
				end -- If The Player Is In My Group It Multiplys
				for i = 1, #children do -- This Adds Score To All The Players
				children[i].leaderstats.Score.Value = children[i].leaderstats.Score.Value + Score -- Awards The Score
				end -- This Awarded The Player Score
				end -- This Has Awarded The Player Score
		end) -- This Has Awarded The Player Score
		if power > 100 then -- If The Power Is Above 100 It Will Enable The Fire And Smoke
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Explode" -- Sets A Value To Explosion -- Another Script Takes This Sound And Plays It
			task.wait(2) -- Waits 2 Seconds
			Ball.Smoke2.Enabled = true -- Enables Smoke
			task.wait(2) -- Waits 2 Seconds
			Ball:Destroy() -- Destroys Ball
		elseif power > 90 then -- Else If The Power Is Above 90 Runs The Following Code
			Ball.Black.Enabled = true -- Enables Black Effects
			Ball.Sound.Value = "SonicBoom" -- Plays Sonic boom -- Another Script Takes This Sound And Plays It
		elseif power > 80 then -- Else If The Power Is Above 80 It Runs The Following Code
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 70 then -- else Power Is Above 70 It Runs The Following Code
			Ball.Red.Enabled = true -- Plays Red Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 65 then -- Else If The Power Is Above 65 It Plays The Following Code
			Ball.Orange.Enabled = true -- Then Orange Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire -- Another Script Takes This Sound And Plays It
		elseif power > 60 then -- Else If The Power Is Above 60 It Runs The Following Code
			Ball.Yellow.Enabled = true -- Plays Yellow Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 55 then -- Else If The Power Is Above 55 Then It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 50 then -- Else If The Power Is Above 50 It Runs The Following Code
			Ball.Pink.Enabled = true -- Pink Partical Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 40 then -- Else If The Power Is Above 40 It Runs The Following Code
			Ball.Green.Enabled = true -- Enables Green Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 30 then -- Else If The Power Is Above 30 It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Partical Effects -- Another Script Takes This Sound And Plays It
		elseif power > 20 then -- Else If The Power Is Above 20 It Runs The Following Code
			Ball.Purple.Enabled = true -- Purple Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 15 then -- Else If The Power Is Above 15 It Runs The Following Code
			Ball.DeepBlue.Enabled = true -- Deep Blue Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 10 then -- Else If The Power Is Above 10 It Runs The Following Code
			Ball.Blue.Enabled = true -- Plays Blue Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Effects Play
		elseif power > 0 then -- If The Power Is Above Runs The Following Code
			Ball.Cyan.Enabled = true -- Enables Cyan Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Sound Plays -- Another Script Takes This Sound And Plays It
		end -- This Has Bowled A Ball And Played Partical Effects
	elseif Player.leaderstats.Bowled.Value <= 10 then -- If The Player Has Bowled Less Than 10 Balls And More Than 5 Balls It Runs The Following Code
		local Ball = game.ServerStorage.Ball2:Clone() -- Clones Ball 2
		Ball.Parent = game.Workspace.ActiveBalls -- Sets The Cloned Balls parent To Active Balls(A Folder in workspace)
		Ball.Position = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector + Vector3.new(0,-3,0) -- Sets The Balls Position Slightly Infront Of The Player On The Ground
		Ball.Velocity = Player.Character.PrimaryPart.CFrame.LookVector * Power + Vector3.new(0,0,0) -- Sets The Balls Vellocity To What The Player Sets It To
		Ball.AssemblyAngularVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Vector3.new(Spin,0,Spin) -- Puts Spin On The Ball
		local hasPass = false -- Makes A Value Named hasPass
		local passID = 804124589 -- Sets The PassId
		local Bowled = 1 -- Sets A Bowled Value
		local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
		end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
		if hasPass == true then -- Checks If The Player Has The Pass
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- This Doubled The Player The Bowled Value If They Got The Pass
		if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- Doubled The bowled If The Player Has Premium
		if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- If The Player Is In My Group It Multiplys
		Player.leaderstats.Bowled.Value = Player.leaderstats.Bowled.Value + Bowled -- Adds To The Bowled Value
		Ball.Touched:Connect(function(toutcher)  -- Finds What This New Ball Toutches
			if toutcher.Name == "Pin" then -- Checks If The Pin Is Touched Then It Plays This
				toutcher.CanTouch = false -- Disables The Pins Can Toutch
				local hasPass = false -- Makes A Value Named hasPass
				local passID = 803810936 -- Sets The PassId
				local Score = 20 -- Sets A Score Value
				local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
					hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
				end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
				local children = game.Players:GetChildren() -- Gets All The Players
				if hasPass == true then -- If The Player Has The Pass It Rewards The Player This
					Score = Score * 2 -- Multiplys The Score
				end -- Awards The Playe Score Pased On If They Had The pass Or Not
				if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
					Score = Score * 2 -- Multiplys The Score Value
				end -- Doubled The bowled If The Player Has Premium
				if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
					Score = Score * 2 -- Multiplys The Score Value
				end -- If The Player Is In My Group It Multiplys
				for i = 1, #children do -- This Adds Score To All The Players
					children[i].leaderstats.Score.Value = children[i].leaderstats.Score.Value + Score -- Awards The Score
				end -- This Awarded The Player Score
			end -- This Has Awarded The Player Score
		end) -- This Has Awarded The Player Score
		if power > 100 then -- If The Power Is Above 100 It Will Enable The Fire And Smoke
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Explode" -- Sets A Value To Explosion -- Another Script Takes This Sound And Plays It
			task.wait(2) -- Waits 2 Seconds
			Ball.Smoke2.Enabled = true -- Enables Smoke
			task.wait(2) -- Waits 2 Seconds
			Ball:Destroy() -- Destroys Ball
		elseif power > 90 then -- Else If The Power Is Above 90 Runs The Following Code
			Ball.Black.Enabled = true -- Enables Black Effects
			Ball.Sound.Value = "SonicBoom" -- Plays Sonic boom -- Another Script Takes This Sound And Plays It
		elseif power > 80 then -- Else If The Power Is Above 80 It Runs The Following Code
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 70 then -- else Power Is Above 70 It Runs The Following Code
			Ball.Red.Enabled = true -- Plays Red Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 65 then -- Else If The Power Is Above 65 It Plays The Following Code
			Ball.Orange.Enabled = true -- Then Orange Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire -- Another Script Takes This Sound And Plays It
		elseif power > 60 then -- Else If The Power Is Above 60 It Runs The Following Code
			Ball.Yellow.Enabled = true -- Plays Yellow Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 55 then -- Else If The Power Is Above 55 Then It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 50 then -- Else If The Power Is Above 50 It Runs The Following Code
			Ball.Pink.Enabled = true -- Pink Partical Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 40 then -- Else If The Power Is Above 40 It Runs The Following Code
			Ball.Green.Enabled = true -- Enables Green Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 30 then -- Else If The Power Is Above 30 It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Partical Effects -- Another Script Takes This Sound And Plays It
		elseif power > 20 then -- Else If The Power Is Above 20 It Runs The Following Code
			Ball.Purple.Enabled = true -- Purple Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 15 then -- Else If The Power Is Above 15 It Runs The Following Code
			Ball.DeepBlue.Enabled = true -- Deep Blue Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 10 then -- Else If The Power Is Above 10 It Runs The Following Code
			Ball.Blue.Enabled = true -- Plays Blue Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Effects Play
		elseif power > 0 then -- If The Power Is Above Runs The Following Code
			Ball.Cyan.Enabled = true -- Enables Cyan Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Sound Plays -- Another Script Takes This Sound And Plays It
		end -- This Has Bowled A Ball And Played Partical Effects
	elseif Player.leaderstats.Bowled.Value <= 25 then -- If The Player Has Less Than 25 Bowled And More Than 10 Bowled It Runs The Following Code
		local Ball = game.ServerStorage.Ball3:Clone() -- Clones Ball3
		Ball.Parent = game.Workspace.ActiveBalls -- Sets The Cloned Balls parent To Active Balls(A Folder in workspace)
		Ball.Position = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector + Vector3.new(0,-3,0) -- Sets The Balls Position Slightly Infront Of The Player On The Ground
		Ball.Velocity = Player.Character.PrimaryPart.CFrame.LookVector * Power + Vector3.new(0,0,0) -- Sets The Balls Vellocity To What The Player Sets It To
		Ball.AssemblyAngularVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Vector3.new(Spin,0,Spin) -- Puts Spin On The Ball
		local hasPass = false -- Makes A Value Named hasPass
		local passID = 804124589 -- Sets The PassId
		local Bowled = 1 -- Sets A Bowled Value
		local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
		end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
		if hasPass == true then -- Checks If The Player Has The Pass
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- This Doubled The Player The Bowled Value If They Got The Pass
		if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- Doubled The bowled If The Player Has Premium
		if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- If The Player Is In My Group It Multiplys
		Player.leaderstats.Bowled.Value = Player.leaderstats.Bowled.Value + Bowled -- Adds To The Bowled Value
		Ball.Touched:Connect(function(toutcher)  -- Finds What This New Ball Toutches
			if toutcher.Name == "Pin" then -- Checks If The Pin Is Touched Then It Plays This
				toutcher.CanTouch = false -- Disables The Pins Can Toutch
				local hasPass = false -- Makes A Value Named hasPass
				local passID = 803810936 -- Sets The PassId
				local Score = 40 -- Sets A Score Value
				local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
					hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
				end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
				local children = game.Players:GetChildren() -- Gets All The Players
				if hasPass == true then -- If The Player Has The Pass It Rewards The Player This
					Score = Score * 2 -- Multiplys The Score
				end -- Awards The Playe Score Pased On If They Had The pass Or Not
				if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
					Score = Score * 2 -- Multiplys The Score Value
				end -- Doubled The bowled If The Player Has Premium
				if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
					Score = Score * 2 -- Multiplys The Score Value
				end -- If The Player Is In My Group It Multiplys
				for i = 1, #children do -- This Adds Score To All The Players
					children[i].leaderstats.Score.Value = children[i].leaderstats.Score.Value + Score -- Awards The Score
				end -- This Awarded The Player Score
			end -- This Has Awarded The Player Score
		end) -- This Has Awarded The Player Score
		if power > 100 then -- If The Power Is Above 100 It Will Enable The Fire And Smoke
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Explode" -- Sets A Value To Explosion -- Another Script Takes This Sound And Plays It
			task.wait(2) -- Waits 2 Seconds
			Ball.Smoke2.Enabled = true -- Enables Smoke
			task.wait(2) -- Waits 2 Seconds
			Ball:Destroy() -- Destroys Ball
		elseif power > 90 then -- Else If The Power Is Above 90 Runs The Following Code
			Ball.Black.Enabled = true -- Enables Black Effects
			Ball.Sound.Value = "SonicBoom" -- Plays Sonic boom -- Another Script Takes This Sound And Plays It
		elseif power > 80 then -- Else If The Power Is Above 80 It Runs The Following Code
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 70 then -- else Power Is Above 70 It Runs The Following Code
			Ball.Red.Enabled = true -- Plays Red Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 65 then -- Else If The Power Is Above 65 It Plays The Following Code
			Ball.Orange.Enabled = true -- Then Orange Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire -- Another Script Takes This Sound And Plays It
		elseif power > 60 then -- Else If The Power Is Above 60 It Runs The Following Code
			Ball.Yellow.Enabled = true -- Plays Yellow Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 55 then -- Else If The Power Is Above 55 Then It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 50 then -- Else If The Power Is Above 50 It Runs The Following Code
			Ball.Pink.Enabled = true -- Pink Partical Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 40 then -- Else If The Power Is Above 40 It Runs The Following Code
			Ball.Green.Enabled = true -- Enables Green Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 30 then -- Else If The Power Is Above 30 It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Partical Effects -- Another Script Takes This Sound And Plays It
		elseif power > 20 then -- Else If The Power Is Above 20 It Runs The Following Code
			Ball.Purple.Enabled = true -- Purple Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 15 then -- Else If The Power Is Above 15 It Runs The Following Code
			Ball.DeepBlue.Enabled = true -- Deep Blue Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 10 then -- Else If The Power Is Above 10 It Runs The Following Code
			Ball.Blue.Enabled = true -- Plays Blue Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Effects Play
		elseif power > 0 then -- If The Power Is Above Runs The Following Code
			Ball.Cyan.Enabled = true -- Enables Cyan Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Sound Plays -- Another Script Takes This Sound And Plays It
		end -- This Has Bowled A Ball And Played Partical Effects
	elseif Player.leaderstats.Bowled.Value >= 50 then -- If The Players Bowled Balls Are Above 50 Than It runs The Following Code
		local Ball = game.ServerStorage.Ball4:Clone() -- Clones Ball4
		Ball.Parent = game.Workspace.ActiveBalls -- Sets The Cloned Balls parent To Active Balls(A Folder in workspace)
		Ball.Position = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector + Vector3.new(0,-3,0) -- Sets The Balls Position Slightly Infront Of The Player On The Ground
		Ball.Velocity = Player.Character.PrimaryPart.CFrame.LookVector * Power + Vector3.new(0,0,0) -- Sets The Balls Vellocity To What The Player Sets It To
		Ball.AssemblyAngularVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Vector3.new(Spin,0,Spin) -- Puts Spin On The Ball
		local hasPass = false -- Makes A Value Named hasPass
		local passID = 804124589 -- Sets The PassId
		local Bowled = 1 -- Sets A Bowled Value
		local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
		end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
		if hasPass == true then -- Checks If The Player Has The Pass
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- This Doubled The Player The Bowled Value If They Got The Pass
		if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- Doubled The bowled If The Player Has Premium
		if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- If The Player Is In My Group It Multiplys
		Player.leaderstats.Bowled.Value = Player.leaderstats.Bowled.Value + Bowled -- Adds To The Bowled Value
		Ball.Touched:Connect(function(toutcher)  -- Finds What This New Ball Toutches
			if toutcher.Name == "Pin" then -- Checks If The Pin Is Touched Then It Plays This
				toutcher.CanTouch = false -- Disables The Pins Can Toutch
				local hasPass = false -- Makes A Value Named hasPass
				local passID = 803810936 -- Sets The PassId
				local Score = 80 -- Sets A Score Value
				local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
					hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
				end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
				local children = game.Players:GetChildren() -- Gets All The Players
				if hasPass == true then -- If The Player Has The Pass It Rewards The Player This
					Score = Score * 2 -- Multiplys The Score
				end -- Awards The Playe Score Pased On If They Had The pass Or Not
				if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
					Score = Score * 2 -- Multiplys The Score Value
				end -- Doubled The bowled If The Player Has Premium
				if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
					Score = Score * 2 -- Multiplys The Score Value
				end -- If The Player Is In My Group It Multiplys
				for i = 1, #children do -- This Adds Score To All The Players
					children[i].leaderstats.Score.Value = children[i].leaderstats.Score.Value + Score -- Awards The Score
				end -- This Awarded The Player Score
			end -- This Has Awarded The Player Score
		end) -- This Has Awarded The Player Score
		if power > 100 then -- If The Power Is Above 100 It Will Enable The Fire And Smoke
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Explode" -- Sets A Value To Explosion -- Another Script Takes This Sound And Plays It
			task.wait(2) -- Waits 2 Seconds
			Ball.Smoke2.Enabled = true -- Enables Smoke
			task.wait(2) -- Waits 2 Seconds
			Ball:Destroy() -- Destroys Ball
		elseif power > 90 then -- Else If The Power Is Above 90 Runs The Following Code
			Ball.Black.Enabled = true -- Enables Black Effects
			Ball.Sound.Value = "SonicBoom" -- Plays Sonic boom -- Another Script Takes This Sound And Plays It
		elseif power > 80 then -- Else If The Power Is Above 80 It Runs The Following Code
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 70 then -- else Power Is Above 70 It Runs The Following Code
			Ball.Red.Enabled = true -- Plays Red Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 65 then -- Else If The Power Is Above 65 It Plays The Following Code
			Ball.Orange.Enabled = true -- Then Orange Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire -- Another Script Takes This Sound And Plays It
		elseif power > 60 then -- Else If The Power Is Above 60 It Runs The Following Code
			Ball.Yellow.Enabled = true -- Plays Yellow Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 55 then -- Else If The Power Is Above 55 Then It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 50 then -- Else If The Power Is Above 50 It Runs The Following Code
			Ball.Pink.Enabled = true -- Pink Partical Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 40 then -- Else If The Power Is Above 40 It Runs The Following Code
			Ball.Green.Enabled = true -- Enables Green Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 30 then -- Else If The Power Is Above 30 It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Partical Effects -- Another Script Takes This Sound And Plays It
		elseif power > 20 then -- Else If The Power Is Above 20 It Runs The Following Code
			Ball.Purple.Enabled = true -- Purple Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 15 then -- Else If The Power Is Above 15 It Runs The Following Code
			Ball.DeepBlue.Enabled = true -- Deep Blue Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 10 then -- Else If The Power Is Above 10 It Runs The Following Code
			Ball.Blue.Enabled = true -- Plays Blue Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Effects Play
		elseif power > 0 then -- If The Power Is Above Runs The Following Code
			Ball.Cyan.Enabled = true -- Enables Cyan Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Sound Plays -- Another Script Takes This Sound And Plays It
		end -- This Has Bowled A Ball And Played Partical Effects
	elseif Player.leaderstats.Bowled.Value <= 100 then -- If The Player Has Less Than 100 Balls Bowled And More Than 50 Balls Bowled it runs The Following Code
		local Ball = game.ServerStorage.Ball5:Clone() -- Clones Ball5
		Ball.Parent = game.Workspace.ActiveBalls -- Sets The Cloned Balls parent To Active Balls(A Folder in workspace)
		Ball.Position = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector + Vector3.new(0,-3,0) -- Sets The Balls Position Slightly Infront Of The Player On The Ground
		Ball.Velocity = Player.Character.PrimaryPart.CFrame.LookVector * Power + Vector3.new(0,0,0) -- Sets The Balls Vellocity To What The Player Sets It To
		Ball.AssemblyAngularVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Vector3.new(Spin,0,Spin) -- Puts Spin On The Ball
		local hasPass = false -- Makes A Value Named hasPass
		local passID = 804124589 -- Sets The PassId
		local Bowled = 1 -- Sets A Bowled Value
		local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
			hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
		end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
		if hasPass == true then -- Checks If The Player Has The Pass
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- This Doubled The Player The Bowled Value If They Got The Pass
		if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- Doubled The bowled If The Player Has Premium
		if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
			Bowled = Bowled * 2 -- Multiplys The Bowled Value
		end -- If The Player Is In My Group It Multiplys
		Player.leaderstats.Bowled.Value = Player.leaderstats.Bowled.Value + Bowled -- Adds To The Bowled Value
		Ball.Touched:Connect(function(toutcher)  -- Finds What This New Ball Toutches
			if toutcher.Name == "Pin" then -- Checks If The Pin Is Touched Then It Plays This
				toutcher.CanTouch = false -- Disables The Pins Can Toutch
				local hasPass = false -- Makes A Value Named hasPass
				local passID = 803810936 -- Sets The PassId
				local Score = 160 -- Sets A Score Value
				local success, message = pcall(function() -- Makes Sure The Player Has The Gamepass
					hasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, passID) -- Actualy Checks
				end) -- This Actualy Checked If The Player Has The Gamepass And Sets Haspass To It
				local children = game.Players:GetChildren() -- Gets All The Players
				if hasPass == true then -- If The Player Has The Pass It Rewards The Player This
					Score = Score * 2 -- Multiplys The Score
				end -- Awards The Playe Score Pased On If They Had The pass Or Not
				if Player.MembershipType == Enum.MembershipType.Premium then -- Checks If The Player Has Premium
					Score = Score * 2 -- Multiplys The Score Value
				end -- Doubled The bowled If The Player Has Premium
				if Player:IsInGroup(33200215) then -- Checks If The Player Is In My Group
					Score = Score * 2 -- Multiplys The Score Value
				end -- If The Player Is In My Group It Multiplys
				for i = 1, #children do -- This Adds Score To All The Players
					children[i].leaderstats.Score.Value = children[i].leaderstats.Score.Value + Score -- Awards The Score
				end -- This Awarded The Player Score
			end -- This Has Awarded The Player Score
		end) -- This Has Awarded The Player Score
		if power > 100 then -- If The Power Is Above 100 It Will Enable The Fire And Smoke
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Explode" -- Sets A Value To Explosion -- Another Script Takes This Sound And Plays It
			task.wait(2) -- Waits 2 Seconds
			Ball.Smoke2.Enabled = true -- Enables Smoke
			task.wait(2) -- Waits 2 Seconds
			Ball:Destroy() -- Destroys Ball
		elseif power > 90 then -- Else If The Power Is Above 90 Runs The Following Code
			Ball.Black.Enabled = true -- Enables Black Effects
			Ball.Sound.Value = "SonicBoom" -- Plays Sonic boom -- Another Script Takes This Sound And Plays It
		elseif power > 80 then -- Else If The Power Is Above 80 It Runs The Following Code
			Ball.Fire.Enabled = true -- Enables Fire
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 70 then -- else Power Is Above 70 It Runs The Following Code
			Ball.Red.Enabled = true -- Plays Red Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 65 then -- Else If The Power Is Above 65 It Plays The Following Code
			Ball.Orange.Enabled = true -- Then Orange Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire -- Another Script Takes This Sound And Plays It
		elseif power > 60 then -- Else If The Power Is Above 60 It Runs The Following Code
			Ball.Yellow.Enabled = true -- Plays Yellow Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 55 then -- Else If The Power Is Above 55 Then It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 50 then -- Else If The Power Is Above 50 It Runs The Following Code
			Ball.Pink.Enabled = true -- Pink Partical Effects Play
			Ball.Sound.Value = "Fire" -- Plays Fire Sound -- Another Script Takes This Sound And Plays It
		elseif power > 40 then -- Else If The Power Is Above 40 It Runs The Following Code
			Ball.Green.Enabled = true -- Enables Green Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 30 then -- Else If The Power Is Above 30 It Runs The Following Code
			Ball.White.Enabled = true -- Plays White Partical Effects
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Partical Effects -- Another Script Takes This Sound And Plays It
		elseif power > 20 then -- Else If The Power Is Above 20 It Runs The Following Code
			Ball.Purple.Enabled = true -- Purple Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 15 then -- Else If The Power Is Above 15 It Runs The Following Code
			Ball.DeepBlue.Enabled = true -- Deep Blue Partical Effects Play
			Ball.Sound.Value = "Ice" -- Plays Ice Cracking Sound -- Another Script Takes This Sound And Plays It
		elseif power > 10 then -- Else If The Power Is Above 10 It Runs The Following Code
			Ball.Blue.Enabled = true -- Plays Blue Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Effects Play
		elseif power > 0 then -- If The Power Is Above Runs The Following Code
			Ball.Cyan.Enabled = true -- Enables Cyan Partical Effects
			Ball.Sound.Value = "Ice" -- Ice Cracking Sound Plays -- Another Script Takes This Sound And Plays It
		end -- This Has Bowled A Ball And Played Partical Effects
	end -- This Has Bowled A Ball And Played Partical Effects For Every Level Of Ball
	if Player.leaderstats.Bowled.Value == 5 then -- Checks If The Player Has Bowled 5 Balls
		local OwnedBadge = BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderBadge1) -- Checks If The Player Owns The Badge
		if not OwnedBadge then -- If They Dont Own Badge it plays this
			BadgeService:AwardBadge(Player.UserId, PlaceHolderBadge1) -- Awards Badge
		end -- This Awarded A Player The Badge
		elseif Player.leaderstats.Bowled.Value == 10 then -- Checks If The Player Has Bowled 10 Balls
		local OwnedBadge = BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderBadge2) -- Checks If The Player Owns The Badge
		if not OwnedBadge then -- If They Dont Own Badge it plays this
				BadgeService:AwardBadge(Player.UserId, PlaceHolderBadge2) -- Awards Badge
		end -- This Awarded A Player The Badge
		elseif Player.leaderstats.Bowled.Value == 25 then -- Checks If The Player Has Bowled 25 Balls
		local OwnedBadge = BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderBadge3) -- Checks If The Player Owns The Badge
		if not OwnedBadge then -- If They Dont Own Badge it plays this
			BadgeService:AwardBadge(Player.UserId, PlaceHolderBadge3) -- Awards Badge
		end -- This Awarded A Player The Badge
		elseif Player.leaderstats.Bowled.Value == 50 then -- Checks If The Player Has Bowled 50 Balls
			local OwnedBadge = BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderBadge4) -- Checks If The Player Owns The Badge
			if not OwnedBadge then -- If They Dont Own Badge it plays this
				BadgeService:AwardBadge(Player.UserId, PlaceHolderBadge4) -- Awards Badge
		end -- This Awarded A Player The Badge
		elseif Player.leaderstats.Bowled.Value == 100 then -- Checks If The Player Has Bowled 100 Balls
		local OwnedBadge = BadgeService:UserHasBadgeAsync(Player.UserId, PlaceHolderBadge5) -- Checks If The Player Owns The Badge
		if not OwnedBadge then -- If They Dont Own Badge it plays this
				BadgeService:AwardBadge(Player.UserId, PlaceHolderBadge5) -- Awards Badge
		end -- This Awarded A Player The Badge
		end -- This Has Awarded All Of The Players The Badges
	end) -- Ends The Function That Bowled All Of The Balls And Gave Them The Badges
game.ReplicatedStorage.Reset.OnServerEvent:Connect(function() -- When The Player Presses Q It Plays This -- Comes From Another Local Script
	workspace.Alley:Destroy() -- Destroys Alley In Workspace
	local Alley = game.ServerStorage.Alley:Clone() -- Clones An Alley From Server Storage
	Alley.Parent = workspace -- Sets The Alley's Parent To Workspace
end) -- This Has Reset The Alley
-- Feel Free To Use This Script Although It Might Be Hard To Implement It Because There Are Alot Of Outside Things, Thanks For Reading This And Sorry For Misspelled Words, Grammer, And Capitalization Im Dislexic :P (Dislexia Is A Mental "Deficency" That Makes It Hard For Me To Do Launguage Oriented Things)

Ik what the spegheti
i know my old script isnt optimized but how is the one i just made?(The First One Listed) Tysm for checking this out and giving feedback!

1 Like

A little bit about me here: Elips Games - Commissions!

1 Like

I know a disgustingly small amount about scripting so I’m not gonna be any real help sorry, but I do know that

wait()

was deprecated, and should be replaced with

task.wait()

which apparently runs twice as fast and, just, is better because of reasons I don’t understand.

Hope that helps, somehow.

2 Likes

If i have a wait in my old script i dont care about that one. I checked through the newer script and i only found 1 wait, its in a repeat and in a repeat it just well repeats the script as fast as posible, this crashes the game so that wait there is so it will run as fast as it can without crashing if i replaced it to task.wait i need it to run as fast as posible and if i set it to nothing well it would wait 0 seconds not doing anything thanks for trying to help tho!

this massive hunk of elseifs can be reduced by putting the stuff into tables

local minimumPowers = {100, 90, 80, 70}
local ballType = {"Fire", "Black", "Fire", "Red"}
local soundType = {"Explode", "SonicBoom", "Fire", "Fire"}
for i,minPower in powers do
  if not power > minPower then continue end

  Ball[balltype[i]].Enabled = true
  Ball.Sound.Value = soundType[i]
  break
end

you should also reduce the amount of comments you make. if the variables are self-explanatory enough, comments will make it harder to read.

1 Like

id also recommend using early returns and more functions
instead of doing this:

if a then
  if b then
   --code
  end
end

try:

local function checkab(a, b)
  if not a or not b then return end
  --the code here runs ONLY if a and b are true
end

checkab(a, b)
1 Like

Thank you! Im not realy trying to fix the long ass script i just pulled it from a long project but still thanks for all the tips!

The function awaitCharacter has some unnecessary checks, having to reset the checks when one goes wrong.

local function awaitCharacter(player)
	--[[if typeof(player) ~= 'Instance' or not player:IsA('Player') then
		return nil
	end]]
    -- This could be replaced with:
    if not player then
        return nil
    end

--[[	local character
	while not character do
		if not player or not player:IsDescendantOf(Players) then
			break
		end

		local char = player.Character
		if not char then
			player.CharacterAdded:Wait()
			continue
		end

		local valid = tryGetCharacterInstances(char)
		if not valid then
			RunService.Stepped:Wait()
			continue
		end

		character = char
	end

	return character]]
    -- All of this could be replaced with
    local character = player.Character or player.CharacterAdded:Wait()
    local valid
    while not valid do
        valid = tryGetCharacterInstances(character)
        task.wait()
    end
    
    return character
end

Hope that helps

1 Like

Thank you for the help!! Ill add it