Rate my coding skills by how I made my recent scripts

Here’s my recent scripts:
-Leveling system : First I need to go to youtube, and I can make my own after(The same code as datastore because why not?)

local datastoreService = game:GetService("DataStoreService")
local tablesstore = {
	
}
local breh = {}
local CoilsDataStore = datastoreService:GetDataStore("CoilsDataStore")
local CodesDataStore = datastoreService:GetDataStore("CodesDataStore")
local StarterItemsDataStore = datastoreService:GetDataStore("StarterItemsDataStore")
local ValuesDataStore = datastoreService:GetDataStore("ValuesDataStore")
local LevelsDataStore = datastoreService:GetDataStore("LevelsDataStore")
game.ReplicatedStorage.BuyItem.OnServerEvent:Connect(function(player,name)
	if name=="Crate1" then
		if player.Coins.Value >= 250 then
			player.Coins.Value-= 250
			--now for the unbox part(not visual)
			local unboxedItem
			local RarityRandom = math.random(1,100)
			if RarityRandom== 100 then
				unboxedItem="GoldenCoil"
			elseif RarityRandom>= 94 and RarityRandom<100 then
				unboxedItem="Gravity"
			elseif RarityRandom>=80 and RarityRandom<94 then
				unboxedItem="GrimaceShake"
			elseif RarityRandom>=50 and RarityRandom<80 then
				local nexte = math.random(1,2)
				if nexte == 1 then
					unboxedItem="Ducky"
				else
					unboxedItem="SpeedCoil"
				end
			elseif RarityRandom<50 then
				local nexte = math.random(1,2)
				if nexte == 1 then
					unboxedItem="BloxyCola"
				else
					unboxedItem="TeddyBear"
				end
			end
			local newvalue = Instance.new("StringValue",player.StarterItems)
			newvalue.Value = unboxedItem
			newvalue.Name = unboxedItem
		
			player.PlayerGui.ScreenGui.Store.Visible = false
			--now for the visual part
			
		end
	end
end)
game.ReplicatedStorage.RedeemCode.OnServerEvent:Connect(function(player,code)
	if code == "dsfafdafdsjasfdajlsfdaljkfdsajklfasdljkfdasljkadsfljksfdalkjfdasjklsfdafjkldasljkfdajklfdsasfdasfklda" then
		if CodesDataStore:GetAsync(player.UserId) then
			if CodesDataStore:GetAsync(player.UserId)[code] == nil then
				local newtable = CodesDataStore:GetAsync(player.UserId)
				table.insert(newtable,code)
				player.Coins.Value+=100
				CodesDataStore:SetAsync(player.UserId,newtable)
			else
				print("Already redeemed")
			end
		end
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	tablesstore[player.UserId] = {}
	breh[player.UserId] = {}
	local Coils = Instance.new("Folder",player)
	Coils.Name="Coils"
	local CollectedCoins = Instance.new("NumberValue",player)
	CollectedCoins.Name = "CollectedCoins"
	local Exp = Instance.new("IntValue",player)
	Exp.Name = "Exp"
	local IsWinnning = Instance.new("BoolValue",player)
	IsWinnning.Name="IsWinning"
	local Level = Instance.new("IntValue",player)
	Level.Name = "Level"
	Level.Value = 1
	local NextExp = Instance.new("IntValue",player)
	NextExp.Name = "NextExp"
	NextExp.Value = 5
NextExp.Value = 2
	if LevelsDataStore:GetAsync(player.UserId) then

		Exp.Value = LevelsDataStore:GetAsync(player.UserId)[1]
		if  LevelsDataStore:GetAsync(player.UserId)[3] == 0 then
			NextExp.Value = 2
		else
			NextExp.Value =  LevelsDataStore:GetAsync(player.UserId)[3]
			end
		if LevelsDataStore:GetAsync(player.UserId)[2]~= 0 then
			Level.Value = LevelsDataStore:GetAsync(player.UserId)[2]
	end
	end
	local CoinsCollected = Instance.new("IntValue",player)
	CoinsCollected.Name = "CollectedCoins"
	local StarterItems = Instance.new("Folder",player)
	StarterItems.Name = "StarterItems"
	local Coins = Instance.new("IntValue",player)
	Coins.Name = "Coins"
	local Wins = Instance.new("IntValue",player)
	Wins.Name = "Wins"
	local IsPremium = Instance.new("BoolValue",player)
	IsPremium.Name = "IsPremium"
	local CurrentItem = Instance.new("StringValue",player)
	CurrentItem.Name = "CurrentItem"
	local getdataValues = ValuesDataStore:GetAsync(player.UserId)
	if getdataValues ~= nil then
		Coins.Value = getdataValues[1]
		Wins.Value = getdataValues[2]
		if getdataValues[4] ~= nil then
			CurrentItem.Value = getdataValues[4]
		end
	end
	local getdatastart = StarterItemsDataStore:GetAsync(player.UserId)
	if getdatastart ~= nil then
		local IsOldData = false
		for i,v in pairs(getdatastart) do
			if v.Ammount == nil then
				IsOldData=true
				break
			else
				break
			end
		end
		if IsOldData == false then
			tablesstore[player.UserId]=getdatastart
			print("Loaded")
			end
		for i,v in pairs(getdatastart) do
			if v.Ammount == nil then
				print("Old datas detected or no datas detected!")
				break
			end
			for i=1,v.Ammount do
			local NewValue = Instance.new("StringValue",StarterItems)
			NewValue.Value = v.Name
			NewValue.Name = v.Name
            end
		end
	end
	local getdatastarte = CoilsDataStore:GetAsync(player.UserId)
	if getdatastarte ~= nil then
		print("Old data detected!")
		breh[player.UserId]=getdatastarte
		local IsOldData = false

		for i,v in pairs(getdatastarte) do

				local NewValue = Instance.new("StringValue",Coils)
				NewValue.Value = v
				NewValue.Name = v
		end
	else
		breh[player.UserId] = {}
	end
	local added = {}
	StarterItems.ChildAdded:Connect(function(e)
		repeat wait() until e.Name ~="Value"
		if tablesstore[player.UserId][e.Name] == nil then
			
tablesstore[player.UserId][e.Name] = {
				Name = e.Name,
				Ammount=1
			}
			print(tablesstore[player.UserId])
		else
			tablesstore[player.UserId][e.Name].Ammount+=1
		end
		StarterItemsDataStore:SetAsync(player.UserId,tablesstore[player.UserId])
		if player.PlayerGui.ScreenGui.Inventory.ScrollingFrame:FindFirstChild(e.Name) then
			player.PlayerGui.ScreenGui.Inventory.ScrollingFrame:FindFirstChild(e.Name).Ammount.Value+=1
		else
			local newbutton = game.ReplicatedStorage.StarterItemsButtons.Example:Clone()
			newbutton.Name = e.Name
			newbutton.Image = require(game.ReplicatedStorage.ItemsImageModule)[e.Name]
			newbutton.Rarity.Value = require(game.ReplicatedStorage.ItemsRarityModule)[e.Name]
			newbutton.Parent = player.PlayerGui.ScreenGui.Inventory.ScrollingFrame
		end
		local unboxmenu =game.ReplicatedStorage.UnboxMenu:Clone()
        unboxmenu.Parent = player.PlayerGui.UnBoxGui
		local ChatService = game:GetService("Chat")
		ChatService:Chat(player.Character,"Yo, I got "..e.Name,Enum.ChatColor.Blue)
		unboxmenu.TextButton.Visible= true
		unboxmenu.TextLabel.Text = "You got "..e.Name.."!"
		local getrarity =require(game.ReplicatedStorage.ItemsRarityModule)[e.Name]
		unboxmenu.ImageButton.Image = require(game.ReplicatedStorage.ItemsImageModule)[e.Name]
		if getrarity=="Uncommon" then
			unboxmenu.TextLabel.TextColor3=Color3.new(0, 1, 1)
		elseif getrarity=="Rare" then
			unboxmenu.TextLabel.TextColor3 = Color3.fromRGB(85, 255, 0)
		elseif getrarity=="Legendary" then
			unboxmenu.TextLabel.TextColor3=Color3.fromRGB(255, 0, 0)
		elseif getrarity=="Super" then
			unboxmenu.TextLabel.TextColor3=Color3.fromRGB(85, 0, 255)
		end
	end)
	Coils.ChildAdded:Connect(function(e)
		repeat wait() until e.Name ~="Value"
		if breh[player.UserId][e.Name] == nil then
            
			breh[player.UserId][e.Name] = e.Name
		end
		CoilsDataStore:SetAsync(player.UserId,breh[player.UserId])
		local clonegui = game.ReplicatedStorage.CoilClaimed:Clone()
		clonegui.Parent=player.PlayerGui.ScreenGui.List
		clonegui.Text = "You found "..e.Name.."!"
	end)
	StarterItems.ChildRemoved:Connect(function(e)
		tablesstore[player.UserId][e.Name].Ammount-=1
		if tablesstore[player.UserId][e.Name].Ammount<=0 then
			tablesstore[player.UserId][e.Name] = nil
		end
	end)
	
	local marketplace = game:GetService("MarketplaceService")
	if marketplace:UserOwnsGamePassAsync(player.UserId,203542850) then
		IsPremium.Value = true
	end
	local function loadItems()
		if #StarterItems:GetChildren() ~= 0 then
			
			for i,v in pairs(StarterItems:GetChildren()) do
				if v.Name ~="Value" then
			if player.PlayerGui:WaitForChild("ScreenGui").Inventory.ScrollingFrame:FindFirstChild(v.Value)==nil then
				local cloned = game.ReplicatedStorage.StarterItemsButtons.Example:Clone()
				cloned.Image = require(game.ReplicatedStorage.ItemsImageModule)[v.Value]
				cloned.Name = v.Value
				cloned.Parent = player.PlayerGui.ScreenGui.Inventory.ScrollingFrame
			else
				local find = player.PlayerGui.ScreenGui.Inventory.ScrollingFrame:FindFirstChild(v.Value)
				find.Ammount.Value +=1
					end
				else
					v:Destroy()
				end
			end
		
		
		end
		
	end
	loadItems()
	if CodesDataStore:GetAsync(player.UserId)==nil or CodesDataStore:GetAsync(player.UserId)=={} then
		CodesDataStore:SetAsync(player.UserId,{})
	end
	local function getNameTag()

		local nameTag = Instance.new("BillboardGui")
		nameTag.Name = "NameTag"
		nameTag.MaxDistance = 30
		nameTag.Adornee = player.Character
		nameTag.ExtentsOffset = Vector3.new(0, 1.2, 0) 
		nameTag.Size = UDim2.new(0, 100, 0, 50) 
		nameTag.Parent = player.Character
		local nameLabel = Instance.new("TextLabel")
		nameLabel.Name = "NameLabel"
		nameLabel.BackgroundTransparency = 1 
		nameLabel.Text = player.Name 
		nameLabel.TextScaled = false
		nameLabel.TextColor3 = Color3.new(1, 1, 1) 
		nameLabel.Font = Enum.Font.Cartoon
		nameLabel.TextSize = 30
		nameLabel.Size = UDim2.new(1, 0, 1, 0)
		nameLabel.Parent = nameTag 
		if IsPremium == true then
			nameLabel.TextColor3 = Color3.new(1, 1, 0)
			nameLabel.Text = player.Name.."(VIP)"
		end
		if player.Name == "ImNotInfected13" then
			nameLabel.TextColor3 = Color3.new(0, 0.666667, 1)
			nameLabel.Text = player.Name.."(Owner)"
		end
		if player.Name == "Famlir321" then
			nameLabel.TextColor3 = Color3.new(0, 0.666667, 1)
			nameLabel.Text = player.Name.."(Developer)"
		end
		if player.Name == "englishnow2" then
			nameLabel.TextColor3 = Color3.new(1, 0, 0)
			nameLabel.Text = player.Name.."(Co-Owner)"
		end
		if player.Name == "Datdz296" then
		
			nameLabel.TextColor3 = Color3.new(1, 0, 0)
			nameLabel.Text = player.Name.."(Pro VIP)"
		end
		local nameTa = Instance.new("BillboardGui")
		nameTa.Name = "LevelTag"
		nameTa.MaxDistance = 30
		nameTa.Adornee = player.Character
		nameTa.ExtentsOffset = Vector3.new(0, 1.4, 0) 
		nameTa.Size = UDim2.new(0, 100, 0, 50) 
		nameTa.Parent = player.Character
		local nameLabe = Instance.new("TextLabel")
		nameLabe.Name = "NameLabel"
		nameLabe.BackgroundTransparency = 1 
		nameLabe.Text = "Lv "..player.Level.Value
		nameLabe.TextScaled = false
		nameLabe.TextColor3 = Color3.new(1, 1, 1) 
		nameLabe.Font = Enum.Font.SciFi
		nameLabe.TextSize = 30
		nameLabe.Size = UDim2.new(1, 0, 1, 0)
		nameLabe.Parent = nameTa
	end
	local function loadHalos()
		local newhalo=nil
		if Level.Value >=15 or player.Name=="ImNotInfected13" or player.Name=="Datdz296" or player.Name=="englishnow2"or player.Name=="chauanh1223" then
			newhalo = game.ReplicatedStorage.Halo:Clone()
			newhalo.Parent = player.Character
		end
		if newhalo~= nil then
			if Level.Value>=15 and Level.Value<30 then
				newhalo.Handle.BrickColor = BrickColor.new("Lime green")
			elseif Level.Value>=30 and Level.Value<50 then
				newhalo.Handle.BrickColor=BrickColor.new("Toothpaste")
			elseif Level.Value>=50 and Level.Value<80 then
				newhalo.Handle.BrickColor=BrickColor.new("Really red")
			elseif Level.Value>=80 then
				newhalo.Handle.BrickColor = BrickColor.new("Hot pink")
			end
		end
		if player.Name=="ImNotInfected13" then
			newhalo.Handle.BrickColor=BrickColor.new("Really blue")
		elseif player.Name=="Datdz296" or player.Name=="englishnow2" then
			newhalo.Handle.BrickColor = BrickColor.new("Really red")
		elseif player.Name=="chauanh1223" then
			newhalo.Handle.BrickColor = BrickColor.new("Hot pink")
		end
	end
loadHalos()
	getNameTag()
	spawn(function()
		while wait() do
			if Exp.Value >= NextExp.Value then
				Level.Value+=1
				player.Character.LevelTag.NameLabel.Text = "Lv "..Level.Value
				print("Done")
				Exp.Value -= NextExp.Value
				if Level.Value < 30 then
					NextExp.Value=NextExp.Value*1.5
				else
					NextExp.Value=NextExp.Value*2
				end
			end

		end
	end)


	player.Team = game.Teams.Lobby
	player:GetPropertyChangedSignal("Team"):Connect(function()
		if player.Team == game.Teams.Lobby then
			for i1,v1 in pairs(player.Character:GetChildren()) do
				if v1:IsA("Tool") then
					v1:Destroy()
				end
			end
			for i2,v2 in pairs(player.Backpack:GetChildren()) do
				if v2:IsA("Tool") then
					v2:Destroy()
				end
			end
		end
	end)

	player.CharacterAdded:Connect(function()
		player.Team = game.Teams.Lobby
		loadItems()
		loadHalos()
		getNameTag()
		
	end)
	
end)
local market = game:GetService("MarketplaceService")
market.PromptProductPurchaseFinished:Connect(function(idnumber,productId,ispurchased)
	local player = game.Players:GetPlayerByUserId(idnumber)
	if ispurchased then
		local coinsmodule = require(game.ReplicatedStorage.CoinsModule)
		if productId==coinsmodule.twenty then
			player.Coins.Value += 20
		elseif productId == coinsmodule.fifty then
			player.Coins.Value += 50
		elseif productId==coinsmodule.onehundred then
			player.Coins.Value += 100
		elseif productId==coinsmodule.fivehundreds then
			player.Coins.Value += 500
		elseif productId==coinsmodule.onethousand then
			player.Coins.Value += 1000
		elseif productId == coinsmodule.fivethousands then
			player.Coins.Value += 5000
		end
	end
	
end)
game.ReplicatedStorage.BuyEventItem.OnServerEvent:Connect(function(player,itemName)
	if itemName == "GreenCoil" then
		if #player.Coils:GetChildren() >= 1 then
		if player.Coins.Value>=250 then
			if player.StarterItems:FindFirstChild("GreenCoil") == nil then
				player.Coins.Value-=250
				local newvalue = Instance.new("StringValue",player.StarterItems)
				newvalue.Value = "GreenCoil"
				newvalue.Name="GreenCoil"
				end
			end 
			end
	elseif itemName== "IceCoil" then
		if #player.Coils:GetChildren() >= 3 then
		if player.Coins.Value>=500 then
			if player.StarterItems:FindFirstChild("IceCoil") == nil then
				player.Coins.Value-=500
				local newvalue = Instance.new("StringValue",player.StarterItems)
				newvalue.Value = "IceCoil"
				newvalue.Name="IceCoil"
				end
				end
		end
	elseif itemName == "FireCoil" then
		if #player.Coils:GetChildren() >= 5 then
		if player.Coins.Value>=1250 then
			if player.StarterItems:FindFirstChild("FireCoil") == nil then
				player.Coins.Value-=1250
				local newvalue = Instance.new("StringValue",player.StarterItems)
				newvalue.Value = "FireCoil"
				newvalue.Name="FireCoil"
				end
				end
		end
	elseif itemName == "ToxicCoil" then
		if #player.Coils:GetChildren() >= 7 then
			if player.Coins.Value>=3000 then
				if player.StarterItems:FindFirstChild("ToxicCoil") == nil then
					player.Coins.Value-=3000
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "ToxicCoil"
					newvalue.Name="ToxicCoil"
				end
			end
		end
	elseif itemName == "VoidCoil" then
		if #player.Coils:GetChildren() >= 9 then
			if player.Coins.Value>=6750 then
				if player.StarterItems:FindFirstChild("VoidCoil") == nil then
					player.Coins.Value-=6750
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "VoidCoil"
					newvalue.Name="VoidCoil"
				end
			end
		end
	elseif itemName == "RainbowCoil" then
		if #player.Coils:GetChildren() >= 12 then
			if player.Coins.Value>=25000 then
				if player.StarterItems:FindFirstChild("RainbowCoil") == nil then
					player.Coins.Value-=25000
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "RainbowCoil"
					newvalue.Name="RainbowCoil"
				end
			end
		end
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	StarterItemsDataStore:SetAsync(player.UserId,tablesstore[player.UserId])
	CoilsDataStore:SetAsync(player.UserId,breh[player.UserId])
	tablesstore[player.UserId]=nil
	ValuesDataStore:SetAsync(player.UserId,{
		player.Coins.Value,
		player.Wins.Value,
		player.IsPremium.Value,
		player.CurrentItem.Value
	})
	LevelsDataStore:SetAsync(player.UserId,{player.Exp.Value,player.Level.Value,player.NextExp.Value})
end)
game.ReplicatedStorage.Equip.OnServerEvent:Connect(function(player,equipName)
	if player.StarterItems:FindFirstChild(equipName) then
		player.CurrentItem.Value = equipName
	else
		player:Kick("Nice try exploiter")
		end
end)

-Monster chasing AI : The only outside code I copied is the code related to pathfindingservice

repeat wait() until script.Parent.Parent.Name == "Workspace"
local waypoints
local anim = script.Parent.Humanoid:LoadAnimation(script.Parent.SlashAni)
local character = {}
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local nextwaypointindex
local reachedconnection
local blockedconnection
local function getclosestplayerwithoutchecking()
	local plr = nil
	local distance = math.huge
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Character then
		if v.Character.Humanoid.Health ~= 0 then
		if (v.Character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude<distance then
			distance = (v.Character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude
			plr = v
		end
		end
		end
	end
	return plr;
end
local CharacterScale = script.Parent:GetExtentsSize()
local AgentParams = {
		AgentCanJump = true,
		AgentCanClimb = true,
		WaypointSpacing = 4,
		Costs = {
			DangerZone1 = math.huge,
			E = math.huge
		}
}
local pathfindingservice = game:GetService("PathfindingService")
local path = pathfindingservice:CreatePath(AgentParams)
local function followpath(des)
	path:ComputeAsync(script.Parent.HumanoidRootPart.Position,des)
	if path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		blockedconnection = path.Blocked:Connect(function(blockedwaypointindex)
			if blockedwaypointindex >= nextwaypointindex then
				blockedconnection:Disconnect()
				followpath(des)
			end
		end)
		if not reachedconnection then
			reachedconnection = script.Parent.Humanoid.MoveToFinished:Connect(function(reached)
				if reached and nextwaypointindex < #waypoints then
					nextwaypointindex+=1
					script.Parent.Humanoid:MoveTo(waypoints[nextwaypointindex].Position)
					if waypoints[nextwaypointindex].Action == Enum.PathWaypointAction.Jump then
						script.Parent.Humanoid.Jump = true
					end
				else
					reachedconnection:Disconnect()
					blockedconnection:Disconnect()
				end
			end)
		end
		nextwaypointindex = 2
		script.Parent.Humanoid:MoveTo(waypoints[nextwaypointindex].Position)
		if waypoints[nextwaypointindex].Action == Enum.PathWaypointAction.Jump then
			script.Parent.Humanoid.Jump = true
		end
	end
end
local reigonpart1 = game.Workspace.Regionpart
local reigonpart2 = game.Workspace.Regionpart2
local region4 = Region3.new(Vector3.new(game.Workspace.Regionpart2.Position-(game.Workspace.Regionpart2.Size/2)),Vector3.new(game.Workspace.Regionpart2.Position+(game.Workspace.Regionpart2.Size/2)))
local region3 = Region3.new(Vector3.new(game.Workspace.Regionpart.Position-(game.Workspace.Regionpart.Size/2)),Vector3.new(game.Workspace.Regionpart.Position+(game.Workspace.Regionpart.Size/2)))
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
local function getclosestplayer()
	local plr = nil
	local distance = math.huge
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.IsHiding.Value == false then
			if v.Character then
			if v.Character.Humanoid.Health ~= 0 then
				local overlap = OverlapParams.new()
				overlap.FilterType = Enum.RaycastFilterType.Exclude
				overlap.FilterDescendantsInstances = {game.Workspace.WholeHouse}
				local playerinre1ornot=false
				local playerinre2ornot=false
				local killerinre1ornot=false
				local killerinre2ornot=false
				for i1,v1 in pairs(game.Workspace:GetPartsInPart(reigonpart1,overlap)) do
					if v1==v.Character.HumanoidRootPart then
						playerinre1ornot = true
						break
					end
				end
				for i1,v1 in pairs(game.Workspace:GetPartsInPart(reigonpart1,overlap)) do
						if v1==script.Parent.HumanoidRootPart then
							killerinre1ornot = true
							break
						end
				end
					for i1,v1 in pairs(game.Workspace:GetPartsInPart(reigonpart2,overlap)) do
						if v1==script.Parent.HumanoidRootPart then
							killerinre2ornot = true
							break
						end
					end
					for i1,v1 in pairs(game.Workspace:GetPartsInPart(reigonpart2,overlap)) do
						if v1==v.Character.HumanoidRootPart then
							playerinre2ornot = true
							break
						end
					end
					if (script.Parent.Status.Value == "Going out" and playerinre1ornot == false and playerinre2ornot == false and v.IsCrouching.Value == false and v.Character.Humanoid.MoveDirection.Magnitude > 0 and killerinre1ornot == false and killerinre2ornot == false) or ((playerinre1ornot == true or playerinre2ornot == true) and v.IsHiding.Value == false and (killerinre1ornot == true or killerinre2ornot == true)) or ((v.Character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude < 30 and (playerinre1ornot == false and playerinre2ornot == false) and (killerinre1ornot==false and killerinre2ornot == false)) then
		if (script.Parent.HumanoidRootPart.Position-v.Character.HumanoidRootPart.Position).Magnitude < distance then
			if v.Character.Humanoid.Health ~= 0 then
			distance = (script.Parent.HumanoidRootPart.Position-v.Character.HumanoidRootPart.Position).Magnitude
				plr = v
					end
					end
		end
		end
		end
		end
		end
	return plr;
end
while wait() do
	script.Parent.IsChasing.Value = false
	script.Parent["Body Colors"].TorsoColor = BrickColor.new("Pearl")
	script.Parent.Humanoid.WalkSpeed = 16
	local result
	local raycastparam = RaycastParams.new()
	raycastparam.FilterType = Enum.RaycastFilterType.Exclude
	raycastparam.FilterDescendantsInstances = {script.Parent}
	local clsplr
	repeat
		wait()
		local randomnumber = math.random(1,5)
		local pathr
		if randomnumber ==1 then
			script.Parent.Status.Value = "Going in"
			pathr = game.Workspace.Inside[math.random(1,#game.Workspace.Inside:GetChildren())]
		else
			script.Parent.Status.Value = "Going out"
			pathr = game.Workspace.Outside[math.random(1,#game.Workspace.Outside:GetChildren())]
		end
		local newpath = pathfindingservice:CreatePath()
		newpath:ComputeAsync(script.Parent.HumanoidRootPart.Position,pathr.Position)

		local waypoints = newpath:GetWaypoints()
		for i,v in pairs(waypoints) do
			 clsplr = getclosestplayer()
			if clsplr then
	
				break
				end
			
			if v.Action == Enum.PathWaypointAction.Jump then
				script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			script.Parent.Humanoid:MoveTo(v.Position)
			script.Parent.Humanoid.MoveToFinished:Wait()
		end
		
	until clsplr
	local target = script.Parent.Target
	target.Value = clsplr
	if game.Workspace.Eletricity.Value <= 0 then
		target.Value = getclosestplayerwithoutchecking()
	end
	script.Parent.HumanoidRootPart.Caught:Play()
	script.Parent.Humanoid.WalkSpeed = 27
	script.Parent["Body Colors"].TorsoColor = BrickColor.new("Really red")
	script.Parent.Head.BillboardGui.ImageLabel.Visible = true
	wait(0.7)
	script.Parent.Head.BillboardGui.ImageLabel.Visible = false
	script.Parent.IsChasing.Value = true
	local timers = 35
	spawn(function()for i=timers,0,-1 do
		if target.Value == nil or target.Value.Character.Humanoid.Health == 0 or target.Value.IsHiding.Value == true then
			break
		end
		timers = i
		wait(1)
	end
	end)
	if target.Value ~= nil then
	repeat
		wait(0.01)
		local distance = (target.Value.Character.HumanoidRootPart.Position-script.Parent.PrimaryPart.Position).Magnitude
		if distance < 6 then
			if character[target.Value.Name] == nil then
				character[target.Value.Name] = true
			    target.Value.Character.Humanoid.Health -=15
				if target.Value.Character.Humanoid.Health <= 0 then
					game.ReplicatedStorage.Jumpscare:FireClient(target.Value)
				end
				script.Parent.Knife.Handle.Slash:Play()
				anim:Play()
				spawn(function()
					wait(0.5)
					character[target.Value.Name] = nil
				end)
			end
		end
		followpath(target.Value.Character.HumanoidRootPart.Position)
	until target.Value == nil or target.Value.Character.Humanoid.Health == 0 or target.Value.IsHiding.Value == true or timers == 0
	else
		local chatservice = game:GetService("Chat")
		chatservice:Chat(script.Parent.Head,"They left.",Enum.ChatColor.Red)
	end
	if timers == 0 then
		local chatservice = game:GetService("Chat")
		chatservice:Chat(script.Parent.Head,"I must get revenge for my son, but where are they?",Enum.ChatColor.Red)
	end
	wait(0.6)
	target.Value = nil
end

-DataStore: I use default DataStore. I can make datastore saves faster by making a table that stores player’s data first and then when player left, the datastore will just setasync that table

5 Likes

i would rate it 9/10
theres 1 thing i would improve: variable naming

for example, instead of

function getclosestplayerwithoutchecking()

i would abbreviate it to something like

function clsplrwoch()

so you have to type less and you can preserve your keyboards life for longer.
another example:

local StarterItemsDataStore -> local stremdastor

it allows you to save space and you can more easily find out what a function does at a glance instead of having to read every single syllable.
and it makes your code look more compact and makes everything ultimately easier to deal with.

other than that, i think you did an absolutely tremendous job, nothing short of incredible. absolutely tremendously fantastic, i must say as a professional myself.

2 Likes

(guessing this is satire)

@ImNotInfected13
Anyways your code looks really messy and unreadable.

Quite a few things you can improve on:

  1. Add variables for things you use frequently, like services, the character, etc on top of your script so you can reference it later
  2. Add spaces when necessary between your code
  3. Don’t name variables useless names like v, especially when you need to know what it actually is
  4. Group up similar functionality, for example, if you’re creating stuff for the leaderstats, put it all together instead of spreading it out

You can do many more things to improve your code, but those are just some of the things I could immediately see.

2 Likes

This is solid, my advice is always find a way to cheat.

Get the hang of module scripts.

Monster Chasing AI script = 215 lines

possible size could be half if you put the player details and the path finding alone in a module script.

Don’t even get me started on this part:

game.ReplicatedStorage.BuyEventItem.OnServerEvent:Connect(function(player,itemName)
	if itemName == "GreenCoil" then
		if #player.Coils:GetChildren() >= 1 then
			if player.Coins.Value>=250 then
				if player.StarterItems:FindFirstChild("GreenCoil") == nil then
					player.Coins.Value-=250
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "GreenCoil"
					newvalue.Name="GreenCoil"
				end
			end 
		end
	elseif itemName== "IceCoil" then
		if #player.Coils:GetChildren() >= 3 then
			if player.Coins.Value>=500 then
				if player.StarterItems:FindFirstChild("IceCoil") == nil then
					player.Coins.Value-=500
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "IceCoil"
					newvalue.Name="IceCoil"
				end
			end
		end
	elseif itemName == "FireCoil" then
		if #player.Coils:GetChildren() >= 5 then
			if player.Coins.Value>=1250 then
				if player.StarterItems:FindFirstChild("FireCoil") == nil then
					player.Coins.Value-=1250
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "FireCoil"
					newvalue.Name="FireCoil"
				end
			end
		end
	elseif itemName == "ToxicCoil" then
		if #player.Coils:GetChildren() >= 7 then
			if player.Coins.Value>=3000 then
				if player.StarterItems:FindFirstChild("ToxicCoil") == nil then
					player.Coins.Value-=3000
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "ToxicCoil"
					newvalue.Name="ToxicCoil"
				end
			end
		end
	elseif itemName == "VoidCoil" then
		if #player.Coils:GetChildren() >= 9 then
			if player.Coins.Value>=6750 then
				if player.StarterItems:FindFirstChild("VoidCoil") == nil then
					player.Coins.Value-=6750
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "VoidCoil"
					newvalue.Name="VoidCoil"
				end
			end
		end
	elseif itemName == "RainbowCoil" then
		if #player.Coils:GetChildren() >= 12 then
			if player.Coins.Value>=25000 then
				if player.StarterItems:FindFirstChild("RainbowCoil") == nil then
					player.Coins.Value-=25000
					local newvalue = Instance.new("StringValue",player.StarterItems)
					newvalue.Value = "RainbowCoil"
					newvalue.Name="RainbowCoil"
				end
			end
		end
	end
end)












Here’s how this would look inside of a module.

local ItemModule = {}


function ItemModule.BuyEventItem(player, itemName)
    local itemDetails = {
        GreenCoil = { requiredCoils = 1, cost = 250 },
        IceCoil = { requiredCoils = 3, cost = 500 },
        FireCoil = { requiredCoils = 5, cost = 1250 },
        ToxicCoil = { requiredCoils = 7, cost = 3000 },
        VoidCoil = { requiredCoils = 9, cost = 6750 },
        RainbowCoil = { requiredCoils = 12, cost = 25000 }
    }
    local details = itemDetails[itemName]
    if details and #player.Coils:GetChildren() >= details.requiredCoils then
        if player.Coins.Value >= details.cost then
            if player.StarterItems:FindFirstChild(itemName) == nil then
                player.Coins.Value -= details.cost
                local newvalue = Instance.new("StringValue", player.StarterItems)
                newvalue.Value = itemName
                newvalue.Name = itemName
            end
        end
    end
end

game.ReplicatedStorage.BuyEventItem.OnServerEvent:Connect(ItemModule.BuyEventItem)

return ItemModule

Not bad though. This would be an nightmare if you decided to update the code a year from now though :smiley:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.