replicatedStorage.ClientRemotes.EnemyDied.OnClientEvent:Connect(function(q)local function r()if players.LocalPlayer.Character then return players.LocalPlayer.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")end end wait(.5)for q,r in pairs(q:GetDescendants())do if r:IsA("\066\097\115\101\080\097\114\116")or r.ClassName=="\068\101\099\097\108"then((game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")):Create(r,TweenInfo.new(1),{Transparency=1})):Play()end end if q:FindFirstChild("\076\111\111\116\084\097\103\115")and(q.LootTags:FindFirstChild(players.LocalPlayer.Name)and replicatedStorage.ServerSettings.XPCollectEffect.Value==true)then local w=q:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if w then local q={}for r=1,math.random(4,8),1 do local B=(script:WaitForChild("\088\080\079\114\098")):Clone()B.CFrame=w.CFrame+Vector3.new(math.random(-3,3),0,math.random(-3,3))B.Parent=workspace table.insert(q,B)end wait(1)for q,w in pairs(q)do if w and w.Parent then local q=r()if q then(require(playSoundEffect))("\088\080")w.Anchored=true w.CanCollide=false;((game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")):Create(w,TweenInfo.new(.1),{CFrame=q.CFrame})):Play()wait(.1)end w:Destroy()end end end end end)replicatedStorage.ClientRemotes.DamageDone.OnClientEvent:Connect(function(q,r)local w=FindToolInHand()if q:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")and(q:FindFirstChild("\069\110\101\109\121\072\117\109\097\110\111\105\100")and w)then(require(updateEnvironment)).PlaySoundInCharacter(w.DamageSound.Value)local B=Instance.new("\066\105\108\108\098\111\097\114\100\071\117\105")B.LightInfluence=0 B.AlwaysOnTop=true B.MaxDistance=30 B.Size=UDim2.new(5,0,1,0)B.Parent=q.HumanoidRootPart local E=Instance.new("\084\101\120\116\076\097\098\101\108")E.Font=Enum.Font.SourceSansBold E.BackgroundTransparency=1 E.TextScaled=true E.Size=UDim2.new(1,0,1,0)E.TextColor3=Color3.fromRGB(255,255,255)E.Text=r E.Parent=B if r>q.EnemyHumanoid.MaxHealth/3 then E.TextColor3=Color3.fromRGB(255,0,0)elseif r>q.EnemyHumanoid.MaxHealth/6 then E.TextColor3=Color3.fromRGB(255,255,0)end;((game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")):Create(B,TweenInfo.new(.5),{StudsOffset=Vector3.new(0,1,0)})):Play()local v={}for q,r in pairs(q:GetDescendants())do if r:IsA("\066\097\115\101\080\097\114\116")then table.insert(v,{r,r.Material,r.Color})r.Material=Enum.Material.Neon r.Color=Color3.fromRGB(255,0,0)end end wait(.2)for q,r in pairs(v)do if r[1]and r[1].Parent then r[1].Material=r[2]r[1].Color=r[3]end end wait(.3);((game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")):Create(E,TweenInfo.new(1,Enum.EasingStyle.Linear),{TextTransparency=1})):Play();(game:GetService("\068\101\098\114\105\115")):AddItem(B,1)end end)replicatedStorage.ClientRemotes.TeleportToArea.OnClientEvent:Connect(function(q)(require(updateEnvironment)).LoadArea(q)end)
-- Client remotes
replicatedStorage.ClientRemotes.EnemyDied.OnClientEvent:Connect(function(enemy)
	local function GetPlayerRootPart()
		if players.LocalPlayer.Character then
			return players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
		end
	end
	wait(0.5)
	for _, part in pairs(enemy:GetDescendants()) do
		if part:IsA("BasePart") or part.ClassName == "Decal" then
			game:GetService("TweenService"):Create(part, TweenInfo.new(1), { Transparency = 1 }):Play()
		end
	end
	if
		enemy:FindFirstChild("LootTags")
		and enemy.LootTags:FindFirstChild(players.LocalPlayer.Name)
		and replicatedStorage.ServerSettings.XPCollectEffect.Value == true
	then
		-- XP effect
		local rootPart = enemy:FindFirstChild("HumanoidRootPart")
		if rootPart then
			local orbs = {}
			for _ = 1, math.random(4, 8) do
				local orb = script:WaitForChild("XPOrb"):Clone()
				orb.CFrame = rootPart.CFrame + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3))
				orb.Parent = workspace
				table.insert(orbs, orb)
			end
			wait(1)
			for _, orb in pairs(orbs) do
				if orb and orb.Parent then
					local playerRootPart = GetPlayerRootPart()
					if playerRootPart then
						require(playSoundEffect)("XP")
						orb.Anchored = true
						orb.CanCollide = false
						game:GetService("TweenService")
							:Create(orb, TweenInfo.new(0.1), { CFrame = playerRootPart.CFrame })
							:Play()
						wait(0.1)
					end
					orb:Destroy()
				end
			end
		end
	end
end)

replicatedStorage.ClientRemotes.DamageDone.OnClientEvent:Connect(function(enemy, damage)
	local tool = FindToolInHand()
	if enemy:FindFirstChild("HumanoidRootPart") and enemy:FindFirstChild("EnemyHumanoid") and tool then
		require(updateEnvironment).PlaySoundInCharacter(tool.DamageSound.Value)
		local indicator = Instance.new("BillboardGui")
		indicator.LightInfluence = 0
		indicator.AlwaysOnTop = true
		indicator.MaxDistance = 30
		indicator.Size = UDim2.new(5, 0, 1, 0)
		indicator.Parent = enemy.HumanoidRootPart
		local label = Instance.new("TextLabel")
		label.Font = Enum.Font.SourceSansBold
		label.BackgroundTransparency = 1
		label.TextScaled = true
		label.Size = UDim2.new(1, 0, 1, 0)
		label.TextColor3 = Color3.fromRGB(255, 255, 255)
		label.Text = damage
		label.Parent = indicator
		if damage > enemy.EnemyHumanoid.MaxHealth / 3 then -- really good damage
			label.TextColor3 = Color3.fromRGB(255, 0, 0)
		elseif damage > enemy.EnemyHumanoid.MaxHealth / 6 then -- pretty good damage
			label.TextColor3 = Color3.fromRGB(255, 255, 0)
		end
		game:GetService("TweenService")
			:Create(indicator, TweenInfo.new(0.5), { StudsOffset = Vector3.new(0, 1, 0) })
			:Play()
		local bodyParts = {}
		for _, part in pairs(enemy:GetDescendants()) do
			if part:IsA("BasePart") then
				table.insert(bodyParts, { part, part.Material, part.Color })
				part.Material = Enum.Material.Neon
				part.Color = Color3.fromRGB(255, 0, 0)
			end
		end
		wait(0.2)
		for _, part in pairs(bodyParts) do
			if part[1] and part[1].Parent then
				part[1].Material = part[2]
				part[1].Color = part[3]
			end
		end
		wait(0.3)
		game:GetService("TweenService")
			:Create(label, TweenInfo.new(1, Enum.EasingStyle.Linear), { TextTransparency = 1 })
			:Play()
		game:GetService("Debris"):AddItem(indicator, 1)
	end
end)

replicatedStorage.ClientRemotes.TeleportToArea.OnClientEvent:Connect(function(areaName)
	require(updateEnvironment).LoadArea(areaName)
end)
