this is a security script that prevents hackers from joining the game ! it includes speedhacking blocking and highjump blocking and infinite yield detector
here is the script:
1. local Players = game:GetService("Players")
2. local DataStoreService = game:GetService("DataStoreService")
3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
4. local ExploitLogs = DataStoreService:GetDataStore("ExploitLogs")
5. local TeleportLogs = DataStoreService:GetDataStore("TeleportLogs")
6. local PurchaseLogs = DataStoreService:GetDataStore("PurchaseLogs")
7. local YieldLogs = DataStoreService:GetDataStore("YieldLogs")
8. local thresholdDistance = 50 -- Adjust based on your game
9. -- Function to log exploit attempts
10. local function logExploit(logStore, playerId)
11. logStore:UpdateAsync(playerId, function(oldData)
12. return (oldData or 0) + 1
13. end)
14. end
15. -- Function to get item price (placeholder)
16. local function GetItemPrice(itemId)
17. -- Define your item price retrieval logic here
18. return 100 -- Example price
19. end
20. -- Function to give item to player (placeholder)
21. local function GiveItemToPlayer(player, itemId)
22. -- Define your item giving logic here
23. end
24. -- Player added event
25. Players.PlayerAdded:Connect(function(player)
26. -- Character added event
27. player.CharacterAdded:Connect(function(character)
28. local humanoid = character:WaitForChild("Humanoid")
29. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
30. -- Anti-speed hack
31. humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
32. if humanoid.WalkSpeed > 16 then
33. humanoid.WalkSpeed = 16
34. logExploit(ExploitLogs, player.UserId)
35. player:Kick("Speed hacking detected")
36. end
37. end)
38. -- Anti-jump power hack
39. humanoid:GetPropertyChangedSignal("JumpPower"):Connect(function()
40. if humanoid.JumpPower > 50 then
41. humanoid.JumpPower = 50
42. logExploit(ExploitLogs, player.UserId)
43. player:Kick("Jump power hacking detected")
44. end
45. end)
46. -- Anti-teleport hack
47. local lastPosition = humanoidRootPart.Position
48. while character.Parent do
49. wait(0.1)
50. local currentPosition = humanoidRootPart.Position
51. if (lastPosition - currentPosition).magnitude > thresholdDistance then
52. logExploit(TeleportLogs, player.UserId)
53. player:Kick("Teleport hacking detected")
54. end
55. lastPosition = currentPosition
56. end
57. end)
58. end)
59. -- Server-side verification for purchases
60. ReplicatedStorage.PurchaseItem.OnServerEvent:Connect(function(player, itemId)
61. local itemPrice = GetItemPrice(itemId)
62. if player.leaderstats.Coins.Value >= itemPrice then
63. player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - itemPrice
64. GiveItemToPlayer(player, itemId)
65. else
66. logExploit(PurchaseLogs, player.UserId)
67. player:Kick("Attempted exploit detected: insufficient funds")
68. end
69. end)
70. -- Anti-infinite yield exploit
71. ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
72. local startTime = tick()
73. local timeout = 5 -- 5 seconds timeout
74. while tick() - startTime < timeout do
75. wait(1)
76. -- Your logic here
77. end
78. if tick() - startTime >= timeout then
79. logExploit(YieldLogs, player.UserId)
80. player:Kick("Infinite yield exploit detected")
81. end
82. end)
83. -- Remote function for secure client-server communication
84. ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, requestType, data)
85. if requestType == "ValidatePurchase" then
86. local itemId = data
87. local itemPrice = GetItemPrice(itemId)
88. if player.leaderstats.Coins.Value >= itemPrice then
89. player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - itemPrice
90. GiveItemToPlayer(player, itemId)
91. return true
92. else
93. return false
94. end
95. end
96. end