What do you want to achieve? I want to prevent exploiters to teleport parts that give them for example cash to them
What is the issue? I found out that exploiters could teleport parts to their character, and trigger the Touched Event
Here’s my code inside the part
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 25
print(player.Name.." completed the obby!")
hit.Parent.HumanoidRootPart.CFrame = game.Workspace.Start.CFrame + Vector3.new(0,3,0)
debounce=true
wait(3)
debounce=false
end
end)
You can check their Position every x seconds. Store that and then check it again. If it changes by huge amount (physically not possible to walk). Kick them.
I don’t really want a while loop checking it because the game is already lagging like hell
also i have multiple reward parts from multiple different obbies,
also the exploiter could kinda delete the localscript checking it
If you handle giving the money to the player and touches on the server, which you should do because on the client the money won’t replicate, and they teleport the part to themselves, they won’t earn the money, since they teleported the part on their client and it hasn’t been changed on the server
Of course, they could still get the money by teleporting themselves to the part and they’ll get it because all clients have network ownership of their characters where physics is calculated on their client, so if they teleport themself to somewhere, it’ll replicate to the server
A counteract of this would be to check their last and current position and see if the distance of the displacement is greater than their walk speed, but you’ll of course need to not take the y-components into consideration, since this could give false positives due to your accelerating velocity when you’re falling due to gravity.
However, these sort of things are susceptible to false positives, like if the player is lagging, they would seem to be teleporting. This is why I wouldn’t advise kicking rather than teleporting the player to their old position, but you could obtain their ping, but that’s extra work for the things you send over the client and server
Just do a Magnitude check to see if they’re a reasonable distance from the part when they touch it. They don’t actually teleport the Part on the server, it just registers the Touched event because the client said they touched it.
Try using the Changed function and pass the part Position property as an argument if the position changes replace it to its old position or disable the cash giving script.