I’m preparing to add this code I’ve developed in a separate game to my game, and I want to make sure that I’m not forgetting to account for anything before I add it. Any feedback is welcome.
local Players = game:GetService("Players")
local LastJumps = {}
local Connections = {}
local MinJumpDelay = 0.25
Players.PlayerAdded:Connect(function(Player)
local Id = Player.UserId
Connections[Player.UserId] = Player.CharacterAdded:Connect(function(Char)
LastJumps[Id] = 0
local Humanoid = Char:WaitForChild("Humanoid", 2)
if Humanoid then
local StateConnection
local DiedConnection
local function OnStateChange(State)
if State == Enum.HumanoidStateType.Jumping then
print(tick() - LastJumps[Id])
print(Humanoid.FloorMaterial)
if LastJumps[Id] and ((tick() - LastJumps[Id]) < MinJumpDelay) and Humanoid.FloorMaterial == Enum.Material.Air then
Player:Kick("InfJump")
StateConnection:Disconnect()
DiedConnection:Disconnect()
end
LastJumps[Id] = tick()
end
if State == Enum.HumanoidStateType.Landed or State == Enum.HumanoidStateType.Running or State == Enum.HumanoidStateType.RunningNoPhysics or State == Enum.HumanoidStateType.Climbing then
if LastJumps[Id] then
LastJumps[Id] = tick() - MinJumpDelay
end
end
end
StateConnection = Humanoid.StateChanged:Connect(OnStateChange)
local function OnDied()
StateConnection:Disconnect()
DiedConnection:Disconnect()
end
DiedConnection = Humanoid.Died:Connect(OnDied)
end
end)
end)
Players.PlayerRemoving:Connect(function(Player)
Connections[Player.UserId]:Disconnect()
end)
Thank you!