kyo_kyo

server side combat

May 7th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.82 KB | None | 0 0
  1. local event = game:GetService("ReplicatedStorage").hit
  2. local enemyevent = game:GetService("ServerScriptService").enemyhit
  3. local dodge = game:GetService("ReplicatedStorage").dodge
  4. local parry = game:GetService("ReplicatedStorage").parry
  5. local sfx = game:GetService("ReplicatedStorage").sfx
  6.  
  7. local ts = require(game:GetService("ReplicatedStorage").Tween)
  8.  
  9. local DamageUI = require(script.Parent.DamageBillboardCreator)
  10.  
  11. local already = {}
  12. local playershit = {}
  13. local playercanm1 = {}
  14.  
  15. game.Players.PlayerAdded:Connect(function(plr)
  16. playercanm1[plr] = true
  17. end)
  18.  
  19. local function calculate(AttackType, Player, Enemy)
  20. if AttackType == 1 then
  21. return (Player.ATK * (1 + (Player.LVL ^ 0.8) / 10) - (Enemy.DEF * 0.5) + 200) * 0.95 * 0.55 + Player.PEN
  22. elseif AttackType == 2 then
  23. return (Player.ATK * (1 + (Player.LVL ^ 0.8) / 10) - (Enemy.DEF * 0.5) + 200) * 0.95 * 0.55 * 1.75 + 500 + Player.PEN
  24. elseif AttackType == 3 then
  25. return (Player.ATK * (1 + (Player.LVL ^ 0.5) / 5) - (Enemy.DEF * 0.5)) * 3 + 2000 + Player.PEN
  26. elseif AttackType == 4 then
  27. return Player.GLE - Enemy.GLR
  28. elseif AttackType == 5 then
  29. return ((Player.GLM ^ 3 * Player.LVL ^ 3.2 * 0.1) + (Player.ATK * Player.LVL ^ 1.5 * 0.1)) * 0.3 + 1000 + Player.PEN
  30. end
  31. end
  32.  
  33. local function enemy(Player, Enemy)
  34. return (Enemy.ATK * (1 + (Player.LVL ^ 0.5))) / (1 + (Player.DEF / 50)) * 0.2
  35. end
  36.  
  37. local regens = {}
  38.  
  39. local function regenparry(plr:Player)
  40. if regens[plr] then return end
  41. regens[plr] = true
  42.  
  43. while plr:GetAttribute("ParryStamina") ~= 6 do
  44. for i = 1, 8 do
  45. ts.wait(1)
  46. plr:SetAttribute("ParryCountdown", plr:GetAttribute("ParryCountdown") - 1)
  47. end
  48. plr:SetAttribute("ParryStamina", plr:GetAttribute("ParryStamina") + 1)
  49. plr:SetAttribute("ParryCountdown", 8)
  50. end
  51. regens[plr] = false
  52. end
  53.  
  54. event.OnServerEvent:Connect(function(plr, AttackType)
  55. if not playercanm1[plr] then return end
  56. if plr:GetAttribute("Parrying") then return end
  57. if plr:GetAttribute("Invincible") then return end
  58.  
  59. local hitbox = Instance.new("Part", workspace)
  60. hitbox.BrickColor = BrickColor.new("Really red")
  61. hitbox.CastShadow = false
  62. hitbox.Material = Enum.Material.Neon
  63. hitbox.CanCollide = false
  64. hitbox.Transparency = 0.75
  65. hitbox.Massless = true
  66.  
  67. local weld = Instance.new("Weld", plr.Character:WaitForChild("HumanoidRootPart"))
  68. weld.Part0 = plr.Character:WaitForChild("HumanoidRootPart")
  69. weld.Part1 = hitbox
  70.  
  71. local knockback
  72.  
  73. if AttackType == 1 then
  74. hitbox.Size = Vector3.new(5, 5, 5)
  75. knockback = 10
  76. elseif AttackType == 2 then
  77. hitbox.Size = Vector3.new(6, 6, 7)
  78. knockback = 15
  79. end
  80. weld.C1 = CFrame.new(0, 0, 3)
  81. task.wait()
  82. weld:Destroy()
  83. hitbox.Anchored = true
  84.  
  85. hitbox.Touched:Connect(function(hit)
  86. local enemy = hit:FindFirstAncestorWhichIsA("Model")
  87. if not enemy then return end
  88. if enemy == plr.Character then return end
  89. if not enemy.Name:match("EnemyEntity") then return end
  90. if already[enemy] then return end
  91.  
  92. local humanoid = enemy:FindFirstChild("Humanoid")
  93. if not humanoid or humanoid.Health <= 0 then return end
  94.  
  95. already[enemy] = true
  96.  
  97. local direction = humanoid.MoveDirection
  98. local force = Instance.new("LinearVelocity", enemy:WaitForChild("HumanoidRootPart"))
  99. force.MaxForce = math.huge
  100. force.Attachment0 = enemy:WaitForChild("HumanoidRootPart").RootAttachment
  101. force.VectorVelocity = plr.Character.HumanoidRootPart.CFrame.LookVector * knockback
  102. dodge:FireClient(plr)
  103. local tweener = Instance.new("Vector3Value", enemy:WaitForChild("HumanoidRootPart"))
  104. tweener.Value = force.VectorVelocity
  105. local force_tween = ts.tween(tweener, {
  106. Value = Vector3.new(0, 0, 0)
  107. }, {
  108. duration = 1,
  109. style = "Exponential",
  110. direction = "Out"
  111. })
  112.  
  113. tweener:GetPropertyChangedSignal("Value"):Connect(function()
  114. force.VectorVelocity = tweener.Value
  115.  
  116. if force.VectorVelocity.Magnitude <= 0.5 then
  117. force:Destroy()
  118. end
  119. end)
  120.  
  121. local Player = {
  122. LVL = plr:GetAttribute("LVL"),
  123. ATK = plr:GetAttribute("ATK"),
  124. DEF = plr:GetAttribute("DEF"),
  125. STN = plr:GetAttribute("STN"),
  126. CRR = plr:GetAttribute("CRR"),
  127. CRD = plr:GetAttribute("CRD"),
  128. PEN = plr:GetAttribute("PEN"),
  129. GLE = plr:GetAttribute("GLE"),
  130. GLM = plr:GetAttribute("GLM"),
  131. }
  132.  
  133. local Enemy = {
  134. ATK = enemy:GetAttribute("ATK"),
  135. DEF = enemy:GetAttribute("DEF"),
  136. GLR = enemy:GetAttribute("GLR")
  137. }
  138.  
  139. local dmg = math.round(calculate(AttackType, Player, Enemy))
  140. hit.Parent.Humanoid.Health -= dmg
  141.  
  142. local ui = DamageUI.create(hit.Parent, dmg)
  143. ui.Parent = hit.Parent
  144.  
  145. local tween_pos = ts.tween(ui, {
  146. StudsOffsetWorldSpace = Vector3.new(0, 1, 0)
  147. }, {
  148. duration = 1,
  149. style = "Exponential",
  150. direction = "Out"
  151. })
  152. local tween_num = ts.tween(ui.num, {
  153. TextTransparency = 1
  154. }, {
  155. duration = 1,
  156. style = "Quad",
  157. direction = "InOut"
  158. })
  159. local tween_stroke = ts.tween(ui.num.UIStroke, {
  160. Transparency = 1
  161. }, {
  162. duration = 1,
  163. style = "Quad",
  164. direction = "InOut"
  165. })
  166. ts.wait(1)
  167. ui:Destroy()
  168. end)
  169.  
  170. ts.wait(0.2)
  171. hitbox:Destroy()
  172. already = {}
  173. playercanm1[plr] = false
  174. ts.wait(0.5)
  175. playercanm1[plr] = true
  176. end)
  177.  
  178. enemyevent.Event:Connect(function(attacker, move)
  179. local hitbox = Instance.new("Part", workspace)
  180. hitbox.BrickColor = BrickColor.new("Really red")
  181. hitbox.CastShadow = false
  182. hitbox.Material = Enum.Material.Neon
  183. hitbox.CanCollide = false
  184. hitbox.Transparency = 0.75
  185. hitbox.Massless = true
  186.  
  187. local weld = Instance.new("Weld", attacker:WaitForChild("HumanoidRootPart"))
  188. weld.Part0 = attacker:WaitForChild("HumanoidRootPart")
  189. weld.Part1 = hitbox
  190.  
  191. if move == 1 then
  192. hitbox.Size = Vector3.new(5, 5, 5)
  193. elseif move == 2 then
  194. hitbox.Size = Vector3.new(6, 6, 7)
  195. end
  196.  
  197. weld.C1 = CFrame.new(0, 0, 3)
  198. task.wait()
  199. weld:Destroy()
  200.  
  201. hitbox.Anchored = true
  202.  
  203. hitbox.Touched:Connect(function(hit)
  204. local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  205. if not plr then return end
  206. if hit.Parent == attacker then return end
  207. if playershit[plr] then return end
  208.  
  209. local humanoid = plr.Character:FindFirstChild("Humanoid")
  210. if not humanoid or humanoid.Health <= 0 then return end
  211.  
  212. playershit[plr] = true
  213.  
  214. if plr:GetAttribute("Invincible") then
  215. dodge:FireClient(plr)
  216. return
  217. end
  218.  
  219. local Player = {
  220. LVL = plr:GetAttribute("LVL"),
  221. ATK = plr:GetAttribute("ATK"),
  222. DEF = plr:GetAttribute("DEF"),
  223. STN = plr:GetAttribute("STN"),
  224. CRR = plr:GetAttribute("CRR"),
  225. CRD = plr:GetAttribute("CRD"),
  226. PEN = plr:GetAttribute("PEN"),
  227. GLE = plr:GetAttribute("GLE"),
  228. GLM = plr:GetAttribute("GLM"),
  229. }
  230.  
  231. local Attacker = {
  232. ATK = attacker:GetAttribute("ATK"),
  233. DEF = attacker:GetAttribute("DEF"),
  234. GLR = attacker:GetAttribute("GLR")
  235. }
  236.  
  237. if plr:GetAttribute("Parrying") and move ~= 2 then
  238. if plr:GetAttribute("ParryStamina") > 0 then
  239. local time = plr:GetAttribute("ParryStartTime")
  240. if time and (os.clock() - time) <= 0.1 then
  241. sfx:FireAllClients(plr.Character.Name, "parry")
  242.  
  243. local reflecttxt = DamageUI.create(attacker, "REFLECTED!")
  244. reflecttxt.Parent = attacker
  245. reflecttxt.StudsOffsetWorldSpace = Vector3.new(0, 1.5, 0)
  246.  
  247. local tween_pos = ts.tween(reflecttxt, {
  248. StudsOffsetWorldSpace = Vector3.new(0, 2, 0)
  249. }, {
  250. duration = 1,
  251. style = "Exponential",
  252. direction = "Out"
  253. })
  254. local tween_num = ts.tween(reflecttxt.num, {
  255. TextTransparency = 1
  256. }, {
  257. duration = 1,
  258. style = "Quad",
  259. direction = "InOut"
  260. })
  261. local tween_stroke = ts.tween(reflecttxt.num.UIStroke, {
  262. Transparency = 1
  263. }, {
  264. duration = 1,
  265. style = "Quad",
  266. direction = "InOut"
  267. })
  268.  
  269. local dmg = math.round(enemy(Player, Attacker) * 0.75)
  270. attacker.Humanoid.Health -= dmg
  271.  
  272. local ui = DamageUI.create(attacker, dmg)
  273. ui.Parent = attacker
  274.  
  275. local tween_pos = ts.tween(ui, {
  276. StudsOffsetWorldSpace = Vector3.new(0, 1, 0)
  277. }, {
  278. duration = 1,
  279. style = "Exponential",
  280. direction = "Out"
  281. })
  282. local tween_num = ts.tween(ui.num, {
  283. TextTransparency = 1
  284. }, {
  285. duration = 1,
  286. style = "Quad",
  287. direction = "InOut"
  288. })
  289. local tween_stroke = ts.tween(ui.num.UIStroke, {
  290. Transparency = 1
  291. }, {
  292. duration = 1,
  293. style = "Quad",
  294. direction = "InOut"
  295. })
  296.  
  297. parry:FireClient(plr)
  298.  
  299. ts.wait(1)
  300. reflecttxt:Destroy()
  301. ui:Destroy()
  302. return
  303. else
  304. sfx:FireAllClients(plr.Character.Name, "parry")
  305. parry:FireClient(plr)
  306. plr:SetAttribute("ParryStamina", plr:GetAttribute("ParryStamina") - 1)
  307. regenparry(plr)
  308. return
  309. end
  310. else
  311. sfx:FireAllClients(plr.Character.Name, "break")
  312. local dmg = math.round(enemy(Player, Attacker) * 0.5)
  313. hit.Parent.Humanoid.Health -= dmg
  314. local ui = DamageUI.create(hit.Parent, dmg)
  315. ui.Parent = hit.Parent
  316. local tween_pos = ts.tween(ui, {
  317. StudsOffsetWorldSpace = Vector3.new(0, 1, 0)
  318. }, {
  319. duration = 1,
  320. style = "Exponential",
  321. direction = "Out"
  322. })
  323. local tween_num = ts.tween(ui.num, {
  324. TextTransparency = 1
  325. }, {
  326. duration = 1,
  327. style = "Quad",
  328. direction = "InOut"
  329. })
  330. local tween_stroke = ts.tween(ui.num.UIStroke, {
  331. Transparency = 1
  332. }, {
  333. duration = 1,
  334. style = "Quad",
  335. direction = "InOut"
  336. })
  337.  
  338. local breaktxt = DamageUI.create(hit.Parent, "BREAK!")
  339. breaktxt.Parent = hit.Parent
  340. breaktxt.StudsOffsetWorldSpace = Vector3.new(0, 1.5, 0)
  341.  
  342. local tween_pos = ts.tween(breaktxt, {
  343. StudsOffsetWorldSpace = Vector3.new(0, 2, 0)
  344. }, {
  345. duration = 1,
  346. style = "Exponential",
  347. direction = "Out"
  348. })
  349. local tween_num = ts.tween(breaktxt.num, {
  350. TextTransparency = 1
  351. }, {
  352. duration = 1,
  353. style = "Quad",
  354. direction = "InOut"
  355. })
  356. local tween_stroke = ts.tween(breaktxt.num.UIStroke, {
  357. Transparency = 1
  358. }, {
  359. duration = 1,
  360. style = "Quad",
  361. direction = "InOut"
  362. })
  363.  
  364. local chr = plr.Character
  365. local direction = chr:FindFirstChildOfClass("Humanoid").MoveDirection
  366. local force = Instance.new("LinearVelocity", chr:WaitForChild("HumanoidRootPart"))
  367. force.MaxForce = math.huge
  368. force.Attachment0 = chr:WaitForChild("HumanoidRootPart").RootAttachment
  369. force.VectorVelocity = (direction ~= Vector3.zero and direction or -chr.HumanoidRootPart.CFrame.LookVector) * 10
  370. local tweener = Instance.new("Vector3Value", enemy:WaitForChild("HumanoidRootPart"))
  371. tweener.Value = force.VectorVelocity
  372. local force_tween = ts.tween(tweener, {
  373. Value = Vector3.new(0, 0, 0)
  374. }, {
  375. duration = 0.75,
  376. style = "Exponential",
  377. direction = "Out"
  378. })
  379.  
  380. tweener:GetPropertyChangedSignal("Value"):Connect(function()
  381. force.VectorVelocity = tweener.Value
  382.  
  383. if force.VectorVelocity.Magnitude <= 0.5 then
  384. force:Destroy()
  385. end
  386. end)
  387. ts.wait(1)
  388. ui:Destroy()
  389. breaktxt:Destroy()
  390. return
  391. end
  392. end
  393.  
  394. local dmg = math.round(enemy(Player, Attacker))
  395. hit.Parent.Humanoid.Health -= dmg
  396.  
  397. local ui = DamageUI.create(hit.Parent, dmg)
  398. ui.Parent = hit.Parent
  399. ui.num.TextColor3 = Color3.fromRGB(255, 0, 0)
  400.  
  401. local tween_pos = ts.tween(ui, {
  402. StudsOffsetWorldSpace = Vector3.new(0, 1, 0)
  403. }, {
  404. duration = 1,
  405. style = "Exponential",
  406. direction = "Out"
  407. })
  408. local tween_num = ts.tween(ui.num, {
  409. TextTransparency = 1
  410. }, {
  411. duration = 1,
  412. style = "Quad",
  413. direction = "InOut"
  414. })
  415. local tween_stroke = ts.tween(ui.num.UIStroke, {
  416. Transparency = 1
  417. }, {
  418. duration = 1,
  419. style = "Quad",
  420. direction = "InOut"
  421. })
  422.  
  423. ts.wait(1)
  424. ui:Destroy()
  425. end)
  426.  
  427. ts.wait(0.2)
  428. hitbox:Destroy()
  429. playershit = {}
  430. end)
Advertisement
Add Comment
Please, Sign In to add comment