How can I fix my anti-door mover script?

Two weeks ago, I asked how to create a keycard script. To make my doors more resistant to exploiters, I created a script that, every few seconds, checks the positions of all my doors, against where the doors should be. If the position was wrong, it would shut down the server. However, even if I haven’t moved anything, the server would shut down instantly.

What’s odd is that print(FINDALTOTALPOS) part prints exactly what it should be., -34.349095821381.

I thought this had to do with code being imprecise at a certain decimal point, so I tried to truncate the string via tonumber(string.format("%.3f", FINALTOTALPOS)), which worked and truncated it, but the script still automatically shut-down. (I deleted this part in the code below.)

Code (Extremely sloppy)
-- Shutdcwn
function shutdown()
game.Players.ChildAdded:connect(function(h)
h:Kick()
end)
for _,i in pairs (game.Players:GetChildren()) do
i:Kick()
end
end
----------------------------------------------------------------------------

-- Actual Script -----------------------------------------------------------
local function newDoor(mDoor)
-- Door Var
	local door = mDoor.Door

-- Position Vars
	local TotalPOSX = door.Position.X
	local TotalPOSY = door.Position.Y
	local TotalPOSZ = door.Position.Z
	local FINDALTOTALPOS = TotalPOSX + TotalPOSY +TotalPOSZ
----------------------------------------------------------------------------

print(FINDALTOTALPOS)

----------------------------------------------------------------------------
-- While True Loop
   	 while true do
	 wait(2.5)
	
	 if FINDALTOTALPOS ~= -34.349095821381 then
		
		print("EXPLOITER DETECTED")
		print(FINDALTOTALPOS)
	--	shutdown()
		
		--shutdown()
	end

		end

			end


----------------------------------------------------------------------------


-- Coroutine Loop
for _, door in ipairs(workspace.Doors:GetChildren()) do
    coroutine.wrap(newDoor)(door)
end


Thanks!

Thanks for everybody’s quick responses. It seems that this wouldn’t work no matter what.

What type of doors are those? Characters30

It’s just a door part with a frame and a sensor. When the sensor is hit by a keycard, the door part will set CanCollide to false, and then back to true after a certain amount of time.

Edit: The script takes the position of each door part.

I’m sorry but in the first place, after reading what you’re trying to do, I don’t think it would work. Anti-cheats on the client can easily be deleted/stopped + client sided changes (such as moving doors) can’t be seen by the server. This means that the server cannot check if it’s been moved since it was done on the client.

I mean, there might be a way to work around it however, Imo, it would be really tiresome to do unless it is really important to the gameplay. What you could do is have checks on the server every second and so on players near doors, if a player somehow goes through a door with the boolvalue on the door being false meaning it isn’t opened, the server can assume it was noclipped through/moved and can ban/kick the player as so. However, this means you’ll have to do many checks on the server every second or so and depending on how you do it, can hurt performance.

If you really want to go overkill as well, do raycasting on the player onto the door and see if the raycast somehow phases through the door on the server even though it is closed (though Idk what the difference would be between the above and raycasting so don’t take my word on this part, it’s just if you want to go overkill)

2 Likes

The script you created wouldn’t be useful. The exploiters can only change the door positions on the client so making this on the server (even when it’s fully working) wouldn’t make it more secure.

If you wanted to make the door system more secure then what you should be doing is checking on the server if a player is meant to be passed a door every couple of seconds, take action on the exploiting player with this and not the whole server.

1 Like

Do a part invisible that detect players, if door is authorized nothing happens else shutdown().
Simple but it should work after that door* and detect if player has keycard.

1 Like

An exploiter can destroy or move this part on the client. The best option is just checking magnitude against the player on the server and the door (I have never tried this so you will have to experiement a bit)

2 Likes

Yes you can check too like AI does for players, in range check if player has keycard else kick him.
(And my grammar is horrible )

1 Like

There’s a better way to see if a door’s position has been changed.

First, I just want to make it clear that shutting down a server (I’m assuming that the script is serversided judging by what you have) over an exploiter changing the door position is redundant, as changes to the door position won’t replicate onto the server, only the local client. This is also unnecessarily strict as there could be false positives.

Anyways, back on topic, I believe that the issue is with how you’re calculating & comparing the positions. Personally, what I would do is store each part’s original position and hook it up to a :GetPropertyChangedSignal() connection. Here’s a sample code: https://hastebin.com/raw/bovesapuko

However, a local check such as above can be easily bypassed. Your best bet would to have a serversided check that would check the player’s position and determine if they’re meant to be there (depending on how the game is)

1 Like